Commit db4663d2 authored by Vincent Pelletier's avatar Vincent Pelletier

Simplification: set default to 0 if not set, which removes the need for Dummy...

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).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29083 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d2e183fa
...@@ -83,35 +83,23 @@ class IdTool(BaseTool): ...@@ -83,35 +83,23 @@ class IdTool(BaseTool):
""" """
Generate a new Id Generate a new Id
""" """
if getattr(aq_base(self), 'dict_ids', None) is None: dict_ids = getattr(aq_base(self), 'dict_ids', None)
self.dict_ids = PersistentMapping() if dict_ids is None:
dict_ids = self.dict_ids = PersistentMapping()
new_id = None 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 # Getting the last id
last_id = None if default is None:
class Dummy: default = 0
pass last_id = dict_ids.get(id_group, default)
dummy = Dummy() if method is None:
last_id = self.dict_ids.get(id_group, dummy) new_id = new_id + 1
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)
else: else:
# Now generate a new id new_id = method(new_id)
if method is not None:
new_id = method(last_id)
else:
new_id = last_id + 1
# Store the new value # Store the new value
self.dict_ids[id_group] = new_id dict_ids[id_group] = new_id
return new_id return new_id
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment