Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Split up AddressForm to storefront and dashboard version
dominik-zeglen525c27cded22
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.pyindex 81fe4600b3..74d42cdfda 100644--- a/saleor/dashboard/order/forms.py+++ b/saleor/dashboard/order/forms.py@@ -7,6 +7,7 @@ from django_prices.forms import PriceFieldfrom payments import PaymentError, PaymentStatusfrom satchless.item import InsufficientStock+from ..widgets import PhonePrefixWidgetfrom ...cart.forms import QuantityFieldfrom ...core.forms import AjaxSelect2ChoiceFieldfrom ...discount.utils import decrease_voucher_usage@@ -18,6 +19,7 @@ from ...order.utils import (recalculate_order, remove_empty_groups)from ...product.models import Product, ProductVariant, Stockfrom ...product.utils import allocate_stock, deallocate_stock+from ...userprofile.i18n import AddressForm, PossiblePhoneNumberFormFieldclass OrderNoteForm(forms.ModelForm):@@ -368,3 +370,8 @@ class AddVariantToDeliveryGroupForm(forms.Form):add_variant_to_delivery_group(self.group, variant, quantity, self.discounts)recalculate_order(self.group.order)+++class DashboardAddressForm(AddressForm):+ phone = PossiblePhoneNumberFormField(+ widget=PhonePrefixWidget, required=False)diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex 2280e48688..074a80990a 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -17,7 +17,7 @@ from .forms import (AddVariantToDeliveryGroupForm, CancelGroupForm, CancelOrderLineForm,CancelOrderForm, CapturePaymentForm, ChangeStockForm, ChangeQuantityForm,MoveLinesForm, OrderNoteForm, RefundPaymentForm, ReleasePaymentForm,- RemoveVoucherForm, ShipGroupForm)+ RemoveVoucherForm, ShipGroupForm, DashboardAddressForm)from .utils import (create_invoice_pdf, create_packing_slip_pdf, get_statics_absolute_url)@@ -25,7 +25,6 @@ from ..views import staff_member_requiredfrom ...core.utils import get_paginator_itemsfrom ...order import GroupStatusfrom ...order.models import Order, OrderLine, OrderNote-from ...userprofile.i18n import AddressForm@staff_member_required@@ -352,7 +351,7 @@ def address_view(request, order_pk, address_type):success_msg = pgettext_lazy('Dashboard message','Updated billing address')- form = AddressForm(request.POST or None, instance=address)+ form = DashboardAddressForm(request.POST or None, instance=address)if form.is_valid():form.save()order.create_history_entry(comment=success_msg, user=request.user)diff --git a/saleor/dashboard/widgets.py b/saleor/dashboard/widgets.pyindex aa2818d84e..02795b4e25 100644--- a/saleor/dashboard/widgets.py+++ b/saleor/dashboard/widgets.py@@ -2,6 +2,14 @@ from django import formsfrom django.conf import settingsfrom django_filters.widgets import RangeWidgetfrom django_prices.widgets import PriceInput+from django.forms import Select, TextInput+from phonenumber_field.widgets import PhoneNumberPrefixWidget+from phonenumbers import COUNTRY_CODE_TO_REGION_CODE+++phone_prefixes = [+ ('+{}'.format(k), '+{}'.format(k)) for+ (k, v) in sorted(COUNTRY_CODE_TO_REGION_CODE.items())]class DateRangeWidget(RangeWidget):@@ -15,3 +23,17 @@ class PriceRangeWidget(RangeWidget):self.currency = getattr(settings, 'DEFAULT_CURRENCY')widgets = (PriceInput(self.currency), PriceInput(self.currency))super(RangeWidget, self).__init__(widgets, attrs)+++class PhonePrefixWidget(PhoneNumberPrefixWidget):+ """+ Overwrite widget to use choices with tuple in a simple form of "+XYZ: +XYZ"+ Workaround for an issue:+ https://github.com/stefanfoulis/django-phonenumber-field/issues/82+ """++ template_name = 'dashboard/order/widget/phone-prefix-widget.html'++ def __init__(self, attrs=None):+ widgets = (Select(attrs=attrs, choices=phone_prefixes), TextInput())+ super(PhoneNumberPrefixWidget, self).__init__(widgets, attrs)diff --git a/templates/dashboard/order/widget/phone-prefix-widget.html b/templates/dashboard/order/widget/phone-prefix-widget.htmlnew file mode 100644index 0000000000..d51f4d03be--- /dev/null+++ b/templates/dashboard/order/widget/phone-prefix-widget.html@@ -0,0 +1,7 @@+<div class="phone-prefix-input">+ {% for widget in widget.subwidgets %}+ <div class="phone-prefix-input__field">+ {% include widget.template_name %}+ </div>+ {% endfor %}+</div>