Commit f6adfb1e authored by Vincent Pelletier's avatar Vincent Pelletier

Make it clear in function prototype that "store" is evaluated as a boolean.

Move all code relative to dict_length_ids in a code which access is controled by "store" value. This prevents portal_ids' persistent object modifications when "store" is false.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18361 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c1319e3b
......@@ -153,7 +153,7 @@ class IdTool(BaseTool):
security.declareProtected(Permissions.AccessContentsInformation,
'generateNewLengthIdList')
def generateNewLengthIdList(self, id_group=None, id_count=1, default=None,
store=1):
store=True):
"""
Generates a list of Ids.
The ids are generated using mysql and then stored in a Length object in a
......@@ -167,11 +167,6 @@ class IdTool(BaseTool):
store : if we want do store the new id into the zodb, we want it
by default
"""
if getattr(self, 'dict_length_ids', None) is None:
# Length objects are stored in a persistent mapping: there is one
# Length object per id_group.
self.dict_length_ids = PersistentMapping()
new_id = None
if id_group in (None, 'None'):
raise ValueError, '%s is not a valid group Id.' % (repr(id_group), )
......@@ -194,9 +189,13 @@ class IdTool(BaseTool):
finally:
commit()
new_id = result[0]['LAST_INSERT_ID()']
if self.dict_length_ids.get(id_group) is None:
self.dict_length_ids[id_group] = Length(new_id)
if store:
if getattr(self, 'dict_length_ids', None) is None:
# Length objects are stored in a persistent mapping: there is one
# Length object per id_group.
self.dict_length_ids = PersistentMapping()
if self.dict_length_ids.get(id_group) is None:
self.dict_length_ids[id_group] = Length(new_id)
self.dict_length_ids[id_group].set(new_id)
return range(new_id - id_count, new_id)
......
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