DCL payment page: Get form data from session on error

This commit is contained in:
PCoder 2017-09-29 01:25:22 +05:30
parent 4efc1b4943
commit fcda0b5637
2 changed files with 15 additions and 0 deletions

View file

@ -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):

View file

@ -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(),