Commit 01c8fc9f authored by Julien Muchembled's avatar Julien Muchembled

Do not modify ZODB Id Generator whenever a id is generated

Also simplify code to handle default value.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36288 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 58e4ad7a
......@@ -58,23 +58,15 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator):
raise ValueError, '%s is not a valid group Id.' % (repr(id_group), )
if default is None:
default = 0
self.last_id_dict = getattr(self, 'last_id_dict', None)
if self.last_id_dict is None:
last_id_dict = getattr(self, 'last_id_dict', None)
if last_id_dict is None:
# If the dictionary not exist initialize generator
self.initializeGenerator()
marker = []
# Retrieve the last id
last_id = self.last_id_dict.get(id_group, marker)
if last_id is marker:
new_id = default
if id_count > 1:
# If create a list use the default and increment
new_id = new_id + id_count - 1
else:
# Increment the last_id
new_id = last_id + id_count
last_id_dict = self.last_id_dict
# Retrieve the last id and increment
new_id = last_id_dict.get(id_group, default - 1) + id_count
# Store the new_id in the dictionary
self.last_id_dict[id_group] = new_id
last_id_dict[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