src/ztfy/utils/catalog/__init__.py
branchZTK-1.1
changeset 228 87a929e63afe
parent 197 67242b459a6d
child 252 6463c617c209
equal deleted inserted replaced
227:ba7bf1239055 228:87a929e63afe
    25 from zope.intid.interfaces import IIntIds
    25 from zope.intid.interfaces import IIntIds
    26 
    26 
    27 # import local interfaces
    27 # import local interfaces
    28 
    28 
    29 # import Zope3 packages
    29 # import Zope3 packages
    30 from zope.component import queryUtility, getAllUtilitiesRegisteredFor
    30 from zope.component import queryUtility, getUtility, getAllUtilitiesRegisteredFor
    31 
    31 
    32 # import local packages
    32 # import local packages
    33 from ztfy.utils import request as request_utils
    33 from ztfy.utils import request as request_utils
    34 
    34 
    35 
    35 
    37 # IntIds utility functions
    37 # IntIds utility functions
    38 #
    38 #
    39 
    39 
    40 def getIntIdUtility(name='', request=None, context=None):
    40 def getIntIdUtility(name='', request=None, context=None):
    41     """Look for a named IIntIds utility"""
    41     """Look for a named IIntIds utility"""
       
    42     intids = None
    42     if request is None:
    43     if request is None:
    43         request = request_utils.queryRequest()
    44         request = request_utils.queryRequest()
    44     intids = None
       
    45     if request is not None:
    45     if request is not None:
    46         intids = request_utils.getRequestData('IntIdsUtility::' + name, request)
    46         intids = request_utils.getRequestData('IntIdsUtility::' + name, request)
    47     if intids is None:
    47     if intids is None:
    48         intids = queryUtility(IIntIds, name, context=context)
    48         intids = queryUtility(IIntIds, name, context=context)
    49         if (request is not None) and (intids is not None):
    49         if (request is not None) and (intids is not None):
    66 def getObject(id, intids_name='', request=None, context=None):
    66 def getObject(id, intids_name='', request=None, context=None):
    67     """Look for an object recorded by given IIntIds utility and id"""
    67     """Look for an object recorded by given IIntIds utility and id"""
    68     if id is None:
    68     if id is None:
    69         return None
    69         return None
    70     if request is None:
    70     if request is None:
    71         request = request_utils.getRequest()
    71         request = request_utils.queryRequest()
    72     intids = getIntIdUtility(intids_name, request, context)
    72     intids = getIntIdUtility(intids_name, request, context)
    73     if intids is not None:
    73     if intids is not None:
    74         return intids.queryObject(id)
    74         return intids.queryObject(id)
    75     return None
    75     return None
    76 
    76 
    82 def queryCatalog(name='', context=None):
    82 def queryCatalog(name='', context=None):
    83     """Look for a registered catalog"""
    83     """Look for a registered catalog"""
    84     return queryUtility(ICatalog, name, context=context)
    84     return queryUtility(ICatalog, name, context=context)
    85 
    85 
    86 
    86 
    87 def indexObject(object, catalog_name='', index_name='', request=None, context=None):
    87 def indexObject(object, catalog_name='', index_name='', request=None, context=None, intids=None):
    88     """Index object into a registered catalog"""
    88     """Index object into a registered catalog"""
    89     if request is None:
    89     if intids is None:
    90         request = request_utils.getRequest()
    90         if request is None:
    91     intids = getIntIdUtility('', request, context)
    91             request = request_utils.queryRequest()
       
    92         intids = getIntIdUtility('', request, context)
    92     if intids is not None:
    93     if intids is not None:
    93         if ICatalog.providedBy(catalog_name):
    94         if ICatalog.providedBy(catalog_name):
    94             catalog = catalog_name
    95             catalog = catalog_name
    95         else:
    96         else:
    96             catalog = queryCatalog(catalog_name, context)
    97             catalog = queryCatalog(catalog_name, context)