Example #1
0
 def catalog(self):
     """Primary registered catalog for the wrapped portal type
     """
     if self._catalog is None:
         logger.debug("SuperModel::catalog: *Fetch catalog*")
         self._catalog = self.get_catalog_for(self.brain)
     return self._catalog
Example #2
0
 def instance(self):
     """Content instance of the wrapped object
     """
     if self._instance is None:
         logger.debug("SuperModel::instance: *Wakup object*")
         self._instance = api.get_object(self.brain)
     return self._instance
Example #3
0
 def brain(self):
     """Catalog brain of the wrapped object
     """
     if self._brain is None:
         logger.debug("SuperModel::brain: *Fetch catalog brain*")
         self._brain = self.get_brain_by_uid(self.uid)
     return self._brain
Example #4
0
    def get(self, name, default=None):
        # Internal lookup in the data dict
        value = self.data.get(name, _marker)

        # Return the value immediately
        if value is not _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/brain to have access
            # to e.g. self.absolute_url (function object) or self.review_state
            if not name.startswith("_") or not name.startswith("__"):
                # check if the instance contains this attribute
                instance = self.instance
                instance_value = getattr(instance, name, _marker)
                if instance_value is not _marker:
                    return instance_value

                # check if the brain contains this attribute
                brain = self.brain
                brain_value = getattr(brain, name, _marker)
                if brain_value is not _marker:
                    return brain_value

            return default
        else:
            # Retrieve field value by accessor name
            accessor = field.getAccessor(self.instance)
            accessor_name = accessor.__name__

            # Metadata lookup by accessor name
            value = getattr(self.brain, accessor_name, _marker)
            if value is _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
Example #5
0
    def __del__(self):
        """Destructor

        Terminates all references for garbage collection
        """
        logger.debug("Destroying {}".format(repr(self)))

        # https://zodb.readthedocs.io/en/latest/api.html#persistent.interfaces.IPersistent
        if self._instance is not None:
            changed = getattr(self._instance, "_p_changed", 0)
            # Object is either in the "Ghost" or in the "Saved" state and can
            # be safely deactivated
            if not changed:
                self._instance._p_deactivate()

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