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
No related merge requests found
......@@ -83,35 +83,23 @@ class IdTool(BaseTool):
"""
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,
......
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