def get_collection(self, uids=None, group_by=None): """Wraps the given UIDs into a collection of SuperModels """ if uids is None: uids = self.get_uids() collection = [] for model in map(self.to_model, uids): if model.is_valid(): collection.append(model) else: logger.error("Could not fetch report model for UID={}".format( model.uid)) if group_by is not None: grouped_collection = self.group_items_by(group_by, collection) return reduce(lambda a, b: a + b, grouped_collection.values(), []) return collection
def to_model(self, uid): """Returns a SuperModel for the given UID """ model = None # Fetch the report (portal-) type for component lookups _type = self.get_report_type() try: model = getAdapter(uid, ISuperModel, name=_type) except ComponentLookupError: logger.error( "Lookup Error: No SuperModel registered for name={}".format( _type)) model = getAdapter(uid, ISuperModel) logger.debug("Created Model for UID={}->{}".format(uid, model)) return model
def get_collection(self, uids, group_by=None): """Wraps the given UIDs into a collection of SuperModels :param uids: list of UIDs :param group_by: Grouping field accessor, e.g getClientUID :returns: list of SuperModels """ collection = [] # filter out all non-UIDs uids = filter(api.is_uid, uids) for model in map(self.to_model, uids): if model.is_valid(): collection.append(model) else: logger.error("Could not fetch report model for UID={}".format( model.uid)) if group_by is not None: grouped_collection = self.group_items_by(group_by, collection) return reduce(lambda a, b: a + b, grouped_collection.values(), []) return collection