[Erp5-report] r29083 - /erp5/trunk/products/ERP5/Tool/IdTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Sep 17 08:11:22 CEST 2009
Author: vincent
Date: Thu Sep 17 08:11:21 2009
New Revision: 29083
URL: http://svn.erp5.org?rev=29083&view=rev
Log:
Simplification: set default to 0 if not set, which removes the need for Dummy class instance, and factorises 2 branches of a test.
Micro optimisation: fetch the persistent mapping only from self only once (prevents instanciating 2 acquisition wrappers out of 3).
Improve coding style (space around operators).
Modified:
erp5/trunk/products/ERP5/Tool/IdTool.py
Modified: erp5/trunk/products/ERP5/Tool/IdTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/IdTool.py?rev=29083&r1=29082&r2=29083&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/IdTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Tool/IdTool.py [utf8] Thu Sep 17 08:11:21 2009
@@ -83,35 +83,23 @@
"""
Generate a new Id
"""
-
- if getattr(aq_base(self), 'dict_ids', None) is None:
- self.dict_ids = PersistentMapping()
+
+ dict_ids = getattr(aq_base(self), 'dict_ids', None)
+ if dict_ids is None:
+ dict_ids = self.dict_ids = PersistentMapping()
new_id = None
- if id_group is not None and id_group!='None':
+ if id_group is not None and id_group != 'None':
# Getting the last id
- last_id = None
- class Dummy:
- pass
- dummy = Dummy()
- last_id = self.dict_ids.get(id_group, dummy)
- if last_id is dummy:
- if default is None:
- new_id=0
- else:
- new_id=default
- if method is not None:
- new_id=method(new_id)
+ if default is None:
+ default = 0
+ last_id = dict_ids.get(id_group, default)
+ if method is None:
+ new_id = new_id + 1
else:
- # Now generate a new id
- if method is not None:
- new_id = method(last_id)
- else:
- new_id = last_id + 1
-
+ new_id = method(new_id)
# Store the new value
- self.dict_ids[id_group] = new_id
-
+ dict_ids[id_group] = new_id
return new_id
security.declareProtected(Permissions.AccessContentsInformation,
More information about the Erp5-report
mailing list