Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove management form from steps
Michal Ociepkaad9a763e73e1
diff --git a/checkout/forms.py b/checkout/forms.pyindex 47a1eb595e..54a2d7ac83 100644--- a/checkout/forms.py+++ b/checkout/forms.py@@ -10,32 +10,6 @@ class ShippingForm(AddressForm):use_billing = forms.BooleanField(initial=True)-class ManagementForm(forms.Form):-- CHOICES = (- ('select', 'Select address'),- ('new', 'Complete address')- )-- choice_method = forms.ChoiceField(choices=CHOICES, initial=CHOICES[0][0])-- def __init__(self, is_user_authenticated, *args, **kwargs):- super(ManagementForm, self).__init__(*args, **kwargs)- self.is_user_authenticated = is_user_authenticated- if not is_user_authenticated:- choice_method = self.fields['choice_method']- choice_method.initial = self.CHOICES[1][0]- choice_method.widget = choice_method.hidden_widget()-- def clean(self):- cleaned_data = super(ManagementForm, self).clean()- choice_method = cleaned_data.get('choice_method')- if choice_method == 'select' and not self.is_user_authenticated:- raise forms.ValidationError('Only authenticated users can select '- 'address.')- return cleaned_data--class DigitalDeliveryForm(forms.ModelForm):class Meta:diff --git a/checkout/steps.py b/checkout/steps.pyindex a93711a644..e76e0a4af5 100644--- a/checkout/steps.py+++ b/checkout/steps.py@@ -1,5 +1,5 @@from django.forms.models import model_to_dict-from .forms import ManagementForm, DigitalDeliveryForm, DeliveryForm+from .forms import DigitalDeliveryForm, DeliveryFormfrom checkout.forms import AnonymousEmailFormfrom django.core.exceptions import ValidationErrorfrom django.db import models@@ -43,30 +43,27 @@ class BaseShippingStep(BaseCheckoutStep):self.address = Address(**address_dict)else:self.address = Address()- self.forms = {- 'management': ManagementForm(request.user.is_authenticated(),- request.POST or None),- 'address_list': UserAddressesForm(user=request.user),- 'address': AddressForm(instance=self.address)}- management_form = self.forms['management']- if management_form.is_valid():- self.method = management_form.cleaned_data['choice_method']- if self.method == 'new':- self.forms['address'] = AddressForm(request.POST,- instance=self.address)- elif self.method == 'select':- self.forms['address_list'] = UserAddressesForm(- request.POST, user=request.user)+ address_list = UserAddressesForm(request.POST or None,+ user=request.user)+ if (address_list.is_valid() and+ not address_list.cleaned_data['address']):+ address_form = AddressForm(request.POST, instance=self.address)+ else:+ address_form = AddressForm(instance=self.address)+ self.forms = {'address_list': address_list, 'address': address_form}def forms_are_valid(self):self.cleaned_data = {}- if self.method == 'new' and self.forms['address'].is_valid():- return True- elif self.method == 'select' and self.forms['address_list'].is_valid():- address_book = self.forms['address_list'].cleaned_data['address']- address_book.address.id = None- self.address = address_book.address- return True+ address_list = self.forms['address_list']+ address_form = self.forms['address']+ if address_list.is_valid():+ if address_list.cleaned_data['address']:+ address_book = address_list.cleaned_data['address']+ address_book.address.id = None+ self.address = address_book.address+ return True+ if address_form.is_valid():+ return Truereturn Falsedef validate(self):