def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): query = getattr(item, attribute) if page and per_page: return Pagination.from_list(query, page, per_page) else: return query.all()
def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): query = getattr(item, attribute) if isinstance(query, InstrumentedList): if page and per_page: return Pagination.from_list(query, page, per_page) return query if page and per_page: return self._query_get_paginated_items(query, page, per_page) return self._query_get_all(query)
def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): query = getattr(item, attribute) if page and per_page: # TODO see if this can be better done in one query return Pagination(query.paginate(page, per_page), page, per_page, query.count()) return query
def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): collection = item.get(attribute, set()) items = [] for id in collection: try: items.append(target_resource.manager.read(id)) except ItemNotFound: collection.remove(id) pass return Pagination.from_list(items, page, per_page)
def paginated_instances_or(self, page, per_page, where=None, sort=None, filter_or_cols=[], filter_and_cols=[]): instances = self.instances_or(where=where, sort=sort, filter_or_cols=filter_or_cols, filter_and_cols=filter_and_cols) if isinstance(instances, list): return Pagination.from_list(instances, page, per_page) return self._query_get_paginated_items(instances, page, per_page)
def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): query = getattr(item, attribute) if isinstance(query, InstrumentedList): if page and per_page: return Pagination.from_list(query, page, per_page) return query target_manager = target_resource.manager if isinstance(target_manager, PrincipalMixin): query = target_manager._query_filter_read_permission(query) if page and per_page: return target_manager._query_get_paginated_items(query, page, per_page) return target_manager._query_get_all(query)
def relation_instances(self, item, attribute, target_resource, page=None, per_page=None): query = getattr(item, attribute) if isinstance(query, InstrumentedList): if page and per_page: return Pagination.from_list(query, page, per_page) return query target_manager = target_resource.manager if isinstance(target_manager, PrincipalMixin): query = target_manager._query_filter_read_permission(query) if page and per_page: return target_manager._query_get_paginated_items( query, page, per_page) return target_manager._query_get_all(query)
def paginated_instances(self, page, per_page, where=None, sort=None): query = self.instances(where, sort) # TODO see if this can be better done in one query return Pagination(query.paginate(page, per_page), page, per_page, query.count())
def _paginate(self, items, page, per_page): return Pagination.from_list(list(items), page, per_page)