def query(self, *args, **filters): # Python 2: Pop keyword parameters that aren't actually filters off of the kwargs offset = filters.pop('offset', 0) limit = filters.pop('limit', None) order_by = filters.pop('order_by', None) exclude_fields = filters.pop('exclude_fields', None) only_fields = filters.pop('only_fields', None) no_dereference = filters.pop('no_dereference', None) order_by = order_by or [] exclude_fields = exclude_fields or [] eop = offset + int(limit) if limit else None args = self._process_arg_filters(args) # Process the filters # Note: Both of those functions manipulate "filters" variable so the order in which they # are called matters filters, order_by = self._process_datetime_range_filters( filters=filters, order_by=order_by) filters = self._process_null_filters(filters=filters) result = self.model.objects(*args, **filters) if exclude_fields: try: result = result.exclude(*exclude_fields) except (mongoengine.errors.LookUpError, AttributeError) as e: field = get_field_name_from_mongoengine_error(e) msg = ( 'Invalid or unsupported exclude attribute specified: %s' % field) raise ValueError(msg) if only_fields: try: result = result.only(*only_fields) except (mongoengine.errors.LookUpError, AttributeError) as e: field = get_field_name_from_mongoengine_error(e) msg = ( 'Invalid or unsupported include attribute specified: %s' % field) raise ValueError(msg) if no_dereference: result = result.no_dereference() result = result.order_by(*order_by) result = result[offset:eop] log_query_and_profile_data_for_queryset(queryset=result) return result
def query(self, *args, **filters): # Python 2: Pop keyword parameters that aren't actually filters off of the kwargs offset = filters.pop('offset', 0) limit = filters.pop('limit', None) order_by = filters.pop('order_by', None) exclude_fields = filters.pop('exclude_fields', None) only_fields = filters.pop('only_fields', None) no_dereference = filters.pop('no_dereference', None) order_by = order_by or [] exclude_fields = exclude_fields or [] eop = offset + int(limit) if limit else None args = self._process_arg_filters(args) # Process the filters # Note: Both of those functions manipulate "filters" variable so the order in which they # are called matters filters, order_by = self._process_datetime_range_filters(filters=filters, order_by=order_by) filters = self._process_null_filters(filters=filters) result = self.model.objects(*args, **filters) if exclude_fields: try: result = result.exclude(*exclude_fields) except (mongoengine.errors.LookUpError, AttributeError) as e: field = get_field_name_from_mongoengine_error(e) msg = ('Invalid or unsupported exclude attribute specified: %s' % field) raise ValueError(msg) if only_fields: try: result = result.only(*only_fields) except (mongoengine.errors.LookUpError, AttributeError) as e: field = get_field_name_from_mongoengine_error(e) msg = ('Invalid or unsupported include attribute specified: %s' % field) raise ValueError(msg) if no_dereference: result = result.no_dereference() result = result.order_by(*order_by) result = result[offset:eop] log_query_and_profile_data_for_queryset(queryset=result) return result