Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Move logic to new function
Mira Szewczykdda898e44358
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.pyindex cec6659cec..6b66c089b5 100644--- a/saleor/cart/forms.py+++ b/saleor/cart/forms.py@@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist, NON_FIELD_ERRORSfrom django.utils.translation import pgettext_lazy, ugettext_lazyfrom satchless.item import InsufficientStockfrom ..shipping.models import COUNTRY_CODE_CHOICES, ShippingMethodCountry+from ..shipping.utils import get_shipment_optionsclass QuantityField(forms.IntegerField):@@ -121,5 +122,4 @@ class CountryForm(forms.Form):def get_shipment_options(self):code = self.cleaned_data['country']- return ShippingMethodCountry.objects.filter(- Q(country_code=code) | Q(country_code='')).order_by('price')+ return get_shipment_options(code)diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex 8aca761c07..04df3ccc2d 100644--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -9,6 +9,7 @@ from django.template.response import TemplateResponsefrom . import decoratorsfrom ..core.utils import to_local_currency, get_user_shipping_countryfrom ..product.models import ProductVariant+from ..shipping.utils import get_shipment_optionsfrom .forms import ReplaceCartLineForm, CountryFormfrom .models import Cartfrom .utils import check_product_availability_and_warn@@ -38,6 +39,7 @@ def index(request, cart):default_country = get_user_shipping_country(request)country_form = CountryForm(initial={'country': default_country})+ default_country_options = get_shipment_options(default_country)return TemplateResponse(request, 'cart/index.html',@@ -45,7 +47,8 @@ def index(request, cart):'cart_lines': cart_lines,'cart_total': cart_total,'local_cart_total': local_cart_total,- 'country_form': country_form})+ 'country_form': country_form,+ 'default_country_options': default_country_options})@decorators.get_or_empty_db_cart()diff --git a/saleor/shipping/utils.py b/saleor/shipping/utils.pynew file mode 100644index 0000000000..8e13039d84--- /dev/null+++ b/saleor/shipping/utils.py@@ -0,0 +1,8 @@+from django.db.models import Q+from .models import ShippingMethodCountry+++def get_shipment_options(country_code):+ return ShippingMethodCountry.objects.select_related(+ 'shipping_method').filter(+ Q(country_code=country_code) | Q(country_code='')).order_by('price')