Commit 541ca1eb authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added getObject, a helper method to retrieve objects easily from the catalog.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13213 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 58300298
......@@ -522,6 +522,20 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
kw.setdefault('limit', DEFAULT_RESULT_LIMIT)
return ZCatalog.searchResults(self, REQUEST, **kw)
# We use a string for permissions here due to circular reference in import
# from ERP5Type.Permissions
security.declareProtected('Search ZCatalog', 'getObject')
def getObject(self, query=None, **kw):
"""
A method to factor common code used to search a single
object in the database.
"""
result = self.searchResults(query=query, **kw)
try:
return result[0].getObject()
except IndexError:
return None
def countResults(self, query=None, **kw):
"""
Calls ZCatalog.countResults with extra arguments that
......
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