From fcda0b5637e56d18acfb33e51192eccded03cb31 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 29 Sep 2017 01:25:22 +0530 Subject: [PATCH] DCL payment page: Get form data from session on error --- datacenterlight/views.py | 4 ++++ utils/forms.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index a5fd54f0..a6732d83 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -348,6 +348,10 @@ class PaymentOrderView(FormView): form_kwargs.update({ 'instance': self.request.user.billing_addresses.first() }) + if 'billing_address_data' in self.request.session: + form_kwargs.update({ + 'billing_address_data': self.request.session['billing_address_data'] + }) return form_kwargs def get_context_data(self, **kwargs): diff --git a/utils/forms.py b/utils/forms.py index f8a6d103..a856eb8d 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -118,6 +118,12 @@ class EditCreditCardForm(forms.Form): class BillingAddressForm(forms.ModelForm): token = forms.CharField(widget=forms.HiddenInput(), required=False) + def __init__(self, *args, **kwargs): + billing_address_data = kwargs.get('billing_address_data', {}) + kwargs['initial'] = billing_address_data + super(BillingAddressForm, self).__init__(*args, **kwargs) + + class Meta: model = BillingAddress fields = ['cardholder_name', 'street_address', @@ -136,6 +142,11 @@ class BillingAddressFormSignup(BillingAddressForm): email = forms.EmailField(label=_('Email Address')) field_order = ['name', 'email'] + def __init__(self, *args, **kwargs): + billing_address_data = kwargs.get('billing_address_data', {}) + kwargs['initial'] = billing_address_data + super(BillingAddressFormSignup, self).__init__(*args, **kwargs) + class UserBillingAddressForm(forms.ModelForm): user = forms.ModelChoiceField(queryset=CustomUser.objects.all(),