Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor filters
michal050542c3a749
diff --git a/saleor/product/filters.py b/saleor/product/filters.pyindex c239d04f58..6bb4acfd36 100644--- a/saleor/product/filters.py+++ b/saleor/product/filters.py@@ -79,11 +79,7 @@ class ProductFilter(FilterSet):return [(choice.pk, choice.name) for choice in attribute.values.all()]def validate_sort_by(self, value):- choices = []- for field in SORT_BY_FIELDS.keys():- choices.append(field)- choices.append('-' + field)- if value not in choices:+ if value.strip('-') not in SORT_BY_FIELDS:raise ValidationError(('%s is not an even number' % value))@@ -94,8 +90,8 @@ def get_sort_by_choices(filter):filter.filters['sort_by'].field.choices[1::2]]-def get_now_sorted_by(product_filter):- sort_by = product_filter.form.cleaned_data.get('sort_by')+def get_now_sorted_by(filter):+ sort_by = filter.form.cleaned_data.get('sort_by')if sort_by:sort_by = SORT_BY_FIELDS[sort_by[0].strip('-')]else:diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 67272c42e5..61e02689c8 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -8,7 +8,8 @@ from django.http import HttpResponsePermanentRedirect, JsonResponsefrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse-from .filters import get_now_sorted_by, get_sort_by_choices, ProductFilter+from .filters import (get_now_sorted_by, get_sort_by_choices,+ ProductFilter)from .models import Categoryfrom .utils import (products_with_details, products_for_cart,handle_cart_form, get_availability,