Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor filter_by_location
michal56f458c81339
diff --git a/saleor/core/utils/filters.py b/saleor/core/utils/filters.pyindex 998e4aca3a..1a366746fb 100644--- a/saleor/core/utils/filters.py+++ b/saleor/core/utils/filters.py@@ -26,13 +26,17 @@ def filter_by_customer(queryset, name, value):def filter_by_location(queryset, name, value):+ q = Q(default_billing_address__city__icontains=value)+ q |= Q(default_billing_address__country__icontains=value)+ country_codes = get_country_codes(value)+ for code in country_codes:+ q |= Q(default_billing_address__country__icontains=code)+ return queryset.filter(q)+++def get_country_codes(value):country_codes = []for code, country in dict(countries).items():if value.lower() in country.lower():country_codes.append(code)- q = Q(default_billing_address__country__icontains=value)- for code in country_codes:- q |= Q(default_billing_address__country__icontains=code)-- return queryset.filter(- Q(default_billing_address__city__icontains=value) | q)+ return country_codesdiff --git a/saleor/dashboard/order/filters.py b/saleor/dashboard/order/filters.pyindex 2a92b454e4..4d6274133c 100644--- a/saleor/dashboard/order/filters.py+++ b/saleor/dashboard/order/filters.py@@ -3,6 +3,7 @@ from __future__ import unicode_literalsfrom django_filters import (CharFilter, ChoiceFilter, DateFromToRangeFilter, FilterSet, RangeFilter,OrderingFilter)+from django import formsfrom django.utils.translation import pgettext_lazyfrom django_prices.models import PriceFieldfrom payments import PaymentStatus