Commit 32cd12a8 authored by Aurel's avatar Aurel

new method that returns the last length generated id by id tool


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23202 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 15b0debd
...@@ -148,6 +148,29 @@ class IdTool(BaseTool): ...@@ -148,6 +148,29 @@ class IdTool(BaseTool):
self.dict_length_ids = PersistentMapping() self.dict_length_ids = PersistentMapping()
return self.dict_length_ids.items() return self.dict_length_ids.items()
security.declareProtected(Permissions.AccessContentsInformation,
'getLastGeneratedId')
def getLastLengthGeneratedId(self,id_group=None,default=None):
"""
Get the last length id generated
"""
# check in persistent mapping if exists
if getattr(self, 'dict_length_ids', None) is not None:
last_id = self.dict_length_ids.get(id_group)
if last_id is not None:
return last_id.value - 1
# otherwise check in mysql
portal_catalog = getToolByName(self, 'portal_catalog').getSQLCatalog()
query = getattr(portal_catalog, 'z_portal_ids_get_last_id', None)
if query is None:
raise AttributeError, 'Error while getting last Id: ' \
'z_portal_ids_get_last_id could not ' \
'be found.'
result = query(id_group=id_group)
if len(result):
return result[0]['last_id'] - 1
return default
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewLengthIdList') 'generateNewLengthIdList')
def generateNewLengthIdList(self, id_group=None, id_count=1, default=None, def generateNewLengthIdList(self, id_group=None, id_count=1, default=None,
...@@ -162,7 +185,7 @@ class IdTool(BaseTool): ...@@ -162,7 +185,7 @@ class IdTool(BaseTool):
"Length" is because the id is stored in a python object inspired by "Length" is because the id is stored in a python object inspired by
BTrees.Length. It doesn't have to be a length. BTrees.Length. It doesn't have to be a length.
store : if we want do store the new id into the zodb, we want it store : if we want to store the new id into the zodb, we want it
by default by default
""" """
new_id = None new_id = None
......
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