diff --git a/pyramid_restful/filters.py b/pyramid_restful/filters.py index 950fdbc..51e5e77 100644 --- a/pyramid_restful/filters.py +++ b/pyramid_restful/filters.py @@ -45,13 +45,21 @@ def parse_query_string(self, params): return results def filter_query(self, request, query, view): + if not request.params: + return query + + querystring_params = self.parse_query_string(request.params) + query, filter_list = self.build_filter_list(querystring_params, query, view) + + return self.apply_filter(query, filter_list) + + def build_filter_list(self, querystring_params, query, view): filterable_fields = getattr(view, self.view_attribute_name, None) - if not filterable_fields or not request.params: - return query + if not filterable_fields: + return query, [] filter_list = [] - querystring_params = self.parse_query_string(request.params) available_fields = list(map(lambda x: '{}.{}'.format(x.parent.class_.__name__, x.name), filterable_fields)) for key, val in querystring_params.items(): @@ -89,9 +97,7 @@ def filter_query(self, request, query, view): filter_list.append(self.build_comparision(filterable_fields[i], val)) - query = self.apply_filter(query, filter_list) - - return query + return query, filter_list def apply_filter(self, query, filter_list): """