Exemplo n.º 1
0
 def process_value(self, value):
     """Process publication value
     """
     # UID -> ReportModel
     if self.is_uid(value):
         return self.to_report_model(value)
     # Content -> ReportModel
     elif api.is_object(value):
         return self.to_report_model(value)
     # String -> Unicode
     elif isinstance(value, basestring):
         return safe_unicode(value)
     # DateTime -> DateTime
     elif isinstance(value, DateTime):
         return value
     # Process list values
     elif isinstance(value, (LazyMap, list, tuple)):
         return map(self.process_value, value)
     # Process dict values
     elif isinstance(value, (dict)):
         return {k: self.process_value(v) for k, v in value.iteritems()}
     # Process function
     elif safe_callable(value):
         return self.process_value(value())
     # Always return the unprocessed value last
     return value
Exemplo n.º 2
0
 def get_catalog_for(self, brain_or_object):
     """Return the primary catalog for the given brain or object
     """
     if not api.is_object(brain_or_object):
         raise TypeError("Invalid object type %r" % brain_or_object)
     catalogs = api.get_catalogs_for(brain_or_object, default="uid_catalog")
     return catalogs[0]
Exemplo n.º 3
0
 def to_report_model(self, thing):
     """Wraps an object into a Report Model
     """
     if self.is_uid(thing):
         return self.get_brain_by_uid(thing)
     if not api.is_object(thing):
         raise TypeError("Expected a portal object, got '{}'".format(
             type(thing)))
     return thing
Exemplo n.º 4
0
    def __init__(self, thing):

        self.data = dict()
        self.__empty_marker = object

        if api.is_uid(thing):
            return self.init_with_uid(thing)
        if api.is_brain(thing):
            return self.init_with_brain(thing)
        if api.is_object(thing):
            return self.init_with_instance(thing)
        if thing == "0":
            return self.init_with_instance(api.get_portal())

        raise TypeError("Can not initialize a SuperModel with '{}'".format(
            repr(thing)))
Exemplo n.º 5
0
def get_contents(brain_or_object):
    """Lookup folder contents for this object.

    :param brain_or_object: A single catalog brain or content object
    :type brain_or_object: ATContentType/DexterityContentType/CatalogBrain
    :returns: List of contained contents
    :rtype: list/Products.ZCatalog.Lazy.LazyMap
    """

    # Nothing to do if the object is contentish
    if not is_folderish(brain_or_object):
        return []

    # Returning objects (not brains) to make sure we do not miss any child.
    # It may happen when children belong to different catalogs and not
    # found on 'portal_catalog'.
    ret = filter(lambda obj: api.is_object(obj),
                 api.get_object(brain_or_object).objectValues())
    return ret
Exemplo n.º 6
0
    def to_super_model(obj):
        # avoid circular imports
        from senaite.core.supermodel import SuperModel

        # Object is already a SuperModel, return immediately
        if isinstance(obj, SuperModel):
            return obj

        # Only portal objects are supported
        if not api.is_object(obj):
            raise TypeError("Expected a portal object, got '{}'".format(
                type(obj)))

        # Wrap the object into a specific Publication Object Adapter
        uid = api.get_uid(obj)
        portal_type = api.get_portal_type(obj)

        adapter = queryAdapter(uid, ISuperModel, name=portal_type)
        if adapter is None:
            return SuperModel(uid)
        return adapter