Create billing_address_form only for a logged user
This commit is contained in:
parent
110888e5aa
commit
5a2657e357
1 changed files with 17 additions and 6 deletions
|
@ -341,21 +341,32 @@ class PaymentOrderView(FormView):
|
||||||
else:
|
else:
|
||||||
return BillingAddressFormSignup
|
return BillingAddressFormSignup
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(PaymentOrderView, self).get_context_data(**kwargs)
|
context = super(PaymentOrderView, self).get_context_data(**kwargs)
|
||||||
if 'billing_address_data' in self.request.session:
|
if 'billing_address_data' in self.request.session:
|
||||||
billing_address_data = self.request.session['billing_address_data']
|
billing_address_data = self.request.session['billing_address_data']
|
||||||
else:
|
else:
|
||||||
billing_address_data = {}
|
billing_address_data = {}
|
||||||
|
|
||||||
|
billing_address_form = None
|
||||||
|
if self.request.user.is_authenticated():
|
||||||
|
if billing_address_data:
|
||||||
|
billing_address_form = BillingAddressForm(
|
||||||
|
prefix='billing_address_form',
|
||||||
|
initial=billing_address_data
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
billing_address_form = BillingAddressForm(
|
||||||
|
prefix='billing_address_form',
|
||||||
|
instance=self.request.user.billing_addresses.first()
|
||||||
|
)
|
||||||
|
|
||||||
context.update({
|
context.update({
|
||||||
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
|
'stripe_key': settings.STRIPE_API_PUBLIC_KEY,
|
||||||
'site_url': reverse('datacenterlight:index'),
|
'site_url': reverse('datacenterlight:index'),
|
||||||
'login_form': HostingUserLoginForm(prefix='login_form'),
|
'login_form': HostingUserLoginForm(prefix='login_form'),
|
||||||
'billing_address_form': BillingAddressForm(
|
'billing_address_form': billing_address_form
|
||||||
prefix='billing_address_form',
|
if self.request.user.is_authenticated() else
|
||||||
instance=self.request.user.billing_addresses.first()
|
|
||||||
) if self.request.user.is_authenticated() else
|
|
||||||
BillingAddressFormSignup(
|
BillingAddressFormSignup(
|
||||||
prefix='billing_address_form_signup',
|
prefix='billing_address_form_signup',
|
||||||
initial=billing_address_data
|
initial=billing_address_data
|
||||||
|
@ -380,7 +391,7 @@ class PaymentOrderView(FormView):
|
||||||
auth_user = authenticate(email=email, password=password)
|
auth_user = authenticate(email=email, password=password)
|
||||||
if auth_user:
|
if auth_user:
|
||||||
login(self.request, auth_user)
|
login(self.request, auth_user)
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
return HttpResponseRedirect('')
|
||||||
else:
|
else:
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
context['login_form'] = login_form
|
context['login_form'] = login_form
|
||||||
|
|
Loading…
Reference in a new issue