def get(self, *args, **kwargs): """Retrieve a collection of objects""" self.before_get(args, kwargs) qs = QSManager(request.args, self.schema) objects_count, objects = self.get_collection(qs, kwargs) schema_kwargs = getattr(self, 'get_schema_kwargs', dict()) schema_kwargs.update({'many': True}) self.before_marshmallow(args, kwargs) schema = compute_schema(self.schema, schema_kwargs, qs, qs.include) result = schema.dump(objects).data view_kwargs = request.view_args if getattr(self, 'view_kwargs', None) is True else dict() add_pagination_links(result, objects_count, qs, url_for(self.view, _external=True, **view_kwargs)) result.update({'meta': {'count': objects_count}}) final_result = self.after_get(result) return final_result
def get(self, *args, **kwargs): qs = QSManager(request.args, self.schema) popular_locations = ( db.session.query( Event.searchable_location_name, func.count(Event.id).label('counts') ) .group_by(Event.searchable_location_name) .order_by(desc('counts')) .limit(6) ) locations = [] for location, _ in popular_locations: if location is not None: new_location = EventLocation(name=location) new_location.id = len(locations) locations.append(new_location) schema = EventLocationSchema() result = schema.dump(locations, many=True).data view_kwargs = ( request.view_args if getattr(self, 'view_kwargs', None) is True else {} ) add_pagination_links( result, len(locations), qs, url_for(self.view, **view_kwargs) ) result.update({'meta': {'count': len(locations)}}) return result
def get(self, *args, **kwargs): """Retrieve a collection of items """ qs = QSManager(request.args) try: item_count, items = self.data_layer.get_items(qs, **kwargs) except EntityNotFound as e: return ErrorFormatter.format_error([e.message]), e.status_code schema_kwargs = self.schema.get('get_kwargs', {}) if qs.fields.get(self.resource_type): if schema_kwargs.get('only'): schema_kwargs['only'] = tuple( set(schema_kwargs['only']) & set(self.schema['cls']._declared_fields.keys()) & set(qs.fields[self.resource_type])) else: schema_kwargs['only'] = tuple( set(self.schema['cls']._declared_fields.keys()) & set(qs.fields[self.resource_type])) if schema_kwargs.get('only') and 'id' not in schema_kwargs['only']: schema_kwargs['only'] += ('id', ) schema_kwargs.pop('many', None) schema = self.schema['cls'](many=True, **schema_kwargs) result = schema.dump(items) endpoint_kwargs = request.view_args if self.endpoint.get( 'include_view_kwargs') is True else {} add_pagination_links( result.data, item_count, qs, url_for(self.endpoint.get('name'), **endpoint_kwargs)) return result.data
def get(self, *args, **kwargs): """Retrieve a collection of objects""" self.before_get(args, kwargs) qs = QSManager(request.args) objects_count, objects = self.get_collection(qs, kwargs) schema_kwargs = getattr(self, 'get_schema_kwargs', dict()) schema_kwargs.update({'many': True}) schema = compute_schema(self.get_schema(objects, kwargs=kwargs), schema_kwargs, qs, qs.include) result = schema.dump(objects).data self_url = schema.get_top_level_links(result, many=True)['self'] add_pagination_links(result, objects_count, qs, self_url) result.update({'meta': {'count': objects_count}}) self.after_get(result) return result
def get(self, *args, **kwargs): """Retrieve a collection of objects """ qs = QSManager(request.args, self.schema) object_count, objects = self.data_layer.get_collection(qs, **kwargs) schema_kwargs = getattr(self.opts, 'schema_get_kwargs', dict()) schema_kwargs.update({'many': True}) schema = compute_schema(self.schema, schema_kwargs, qs, qs.include) result = schema.dump(objects) view_kwargs = request.view_args if getattr(self.opts, 'view_kwargs', None) is True else dict() add_pagination_links(result.data, object_count, qs, url_for(self.view, **view_kwargs)) return result.data