コード例 #1
0
 def instance(self):
     """Content instance of the wrapped object
     """
     if self._instance is None:
         logger.debug("ReportModel::instance: *Wakup object*")
         self._instance = api.get_object(self.brain)
     return self._instance
コード例 #2
0
    def get(self, name, default=None):
        # Internal lookup in the data dict
        value = self.data.get(name, self.__empty_marker)
        if value is not self.__empty_marker:
            return self.data[name]

        # Field lookup on the instance
        field = self.get_field(name)
        if field is None:
            # expose non-private members of the instance to have access to e.g.
            # self.absolute_url()
            if not name.startswith("_") or not name.startswith("__"):
                return getattr(self.instance, name, default)
            return default

        # Retrieve field value by accessor
        accessor = field.getAccessor(self.instance)
        accessor_name = accessor.__name__

        # Metadata lookup by accessor name
        value = getattr(self.brain, accessor_name, self.__empty_marker)
        if value is self.__empty_marker:
            logger.debug("Add metadata column '{}' to the catalog '{}' "
                         "to increase performance!".format(
                             accessor_name, self.catalog.__name__))
            value = accessor()

        # Process value for publication
        value = self.process_value(value)

        # Store value in the internal data dict
        self.data[name] = value

        return value
コード例 #3
0
    def __init__(self, uid):
        logger.debug("ReportModel({})".format(uid))

        self._uid = uid
        self._brain = None
        self._catalog = None
        self._instance = None

        self.__empty_marker = object
        self.data = dict()
コード例 #4
0
 def brain(self):
     """Catalog brain of the wrapped object
     """
     if self._brain is None:
         logger.debug("ReportModel::brain: *Fetch catalog brain*")
         self._brain = self.get_brain_by_uid(self.uid)
         # refetch the brain with the correct catalog
         results = self.catalog({"UID": self.uid})
         if results and len(results) == 1:
             self._brain = results[0]
     return self._brain
コード例 #5
0
 def catalog(self):
     """Primary registered catalog for the wrapped portal type
     """
     if self._catalog is None:
         logger.debug("ReportModel::catalog: *Fetch catalog*")
         archetype_tool = api.get_tool("archetype_tool")
         portal_type = self.brain.portal_type
         catalogs = archetype_tool.getCatalogsByType(portal_type)
         if catalogs is None:
             logger.warn(
                 "No registered catalog found for portal_type={}".format(
                     portal_type))
             return api.get_tool("uid_catalog")
         self._catalog = catalogs[0]
     return self._catalog
コード例 #6
0
def synchronized(func, max_connections=2):
    """Synchronize function call via semaphore
    """
    semaphore = threading.BoundedSemaphore(max_connections)
    logger.debug("Semaphore for {} -> {}".format(func, semaphore))

    def decorator(*args, **kwargs):
        try:
            logger.info("==> {}::Acquire Semaphore ...".format(func.__name__))
            semaphore.acquire()
            return func(*args, **kwargs)
        finally:
            logger.info("<== {}::Release Semaphore ...".format(func.__name__))
            semaphore.release()

    return decorator