Example #1
0
    def get_analyses_data(self):
        rows = []

        ars = self.search()
        total = len(ars)
        logger.info("Exporting data of {} ARs".format(total))

        for num, ar in enumerate(ars):
            ar = SuperModel(api.get_uid(ar))

            for an in self.get_analyses(ar):
                data = []
                an = SuperModel(api.get_uid(an))
                for row in ANALYSES_ROWS:
                    model = ar
                    title, key, converter = row
                    if key.startswith("Analysis"):
                        key = ".".join(key.split(".")[1:])
                        model = an
                    value = self.get(model, key)
                    data.append(converter(model, key, value))
                rows.append(data)

            if num % 100 == 0:
                logger.info("Exported {}/{}".format(num, total))

        return rows
Example #2
0
 def get_items(self):
     """Returns a list of SuperModel items
     """
     uids = self.get_uids()
     if not uids:
         return [SuperModel(self.context)]
     items = map(lambda uid: SuperModel(uid), uids)
     return self._resolve_number_of_copies(items)
Example #3
0
 def metadata_sort(a, b):
     if wakeup:
         a = SuperModel(a)
         b = SuperModel(b)
     # get the attribute from the brain or SuperModel
     a = getattr(a, sort_on, "")
     b = getattr(b, sort_on, "")
     # check for callable
     if callable(a):
         a = a()
     if callable(b):
         b = b()
     # Compare the two values
     return cmp(a, b)
Example #4
0
    def ajax_get(self, uid, *args, **kwargs):
        """Return the JSONified data from the wrapped object

        Any additional positional parameter in *args will pick only these keys
        from the returned dictionary.
        """
        logger.info("ajaxPrintView::ajax_get: {}{}".format(
            uid, "/".join(args)))

        model = SuperModel(uid)
        if not model.is_valid():
            return self.fail("No object found for UID '{}'".format(uid),
                             status=404)

        if args:
            return self.pick(model, *args)
        return model.to_dict()
Example #5
0
def get_object_data(obj):
    """Get object schema data

    NOTE: We RAM cache this data because it should only change when the object
    was modified!

    XXX: We need to set at least the modification date when we set fields in
    Ajax Listing when we take a snapshot there!

    :param obj: Content object
    :returns: Dictionary of extracted schema data
    """

    model = SuperModel(obj)
    try:
        data = model.to_dict()
    except Exception as exc:
        logger.error("Failed to get schema data for {}: {}".format(
            repr(obj), str(exc)))
        data = {}

    return data
Example #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):
            return None

        # 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
Example #7
0
    def to_super_model(obj):
        # avoid circular imports
        from senaite.impress.reportmodel import ReportModel

        # Object is already a Publication Object, return immediately
        if isinstance(obj, ReportModel):
            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
Example #8
0
    def get_samples_data(self):
        rows = []

        ars = self.search()
        total = len(ars)
        logger.info("Exporting data of {} ARs".format(total))

        for num, ar in enumerate(ars):
            data = []
            ar = SuperModel(api.get_uid(ar))
            model = ar
            for row in SAMPLES_ROWS:
                title, key, converter = row
                if key.startswith("Analysis"):
                    continue
                value = self.get(model, key)
                data.append(converter(ar, key, value))
            rows.append(data)

            if num % 100 == 0:
                logger.info("Exported {}/{}".format(num, total))

        return rows
Example #9
0
 def ajax_get_reports(self, *args):
     """Returns a list of JSON mmodels
     """
     uids = self.get_json().get("items") or args
     models = map(lambda uid: SuperModel(uid), uids)
     return map(lambda model: model.to_dict(), models)