Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Display billing address according to user

Michal Ociepka79f1d70d35bf
diff --git a/order/forms.py b/order/forms.py
index 70b6cb35a7..3e7afde393 100644
--- a/order/forms.py
+++ b/order/forms.py
@@ -1,6 +1,6 @@
from django import forms
from userprofile.forms import AddressForm
-
+from django.contrib.auth.models import AnonymousUser
class ShippingForm(AddressForm):
@@ -11,7 +11,16 @@ class ManagementForm(forms.Form):
CHOICES = (
('select', 'Select address'),
- ('new', 'Add new address')
+ ('new', 'Complete address')
)
- choice_method = forms.ChoiceField(choices=CHOICES)
+ choice_method = forms.ChoiceField(choices=CHOICES, initial=CHOICES[0][0])
+
+ def __init__(self, is_user_authenticated, *args, **kwargs):
+ super(ManagementForm, self).__init__(*args, **kwargs)
+ 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()
+
+
diff --git a/order/templates/order/address.html b/order/templates/order/address.html
index 070796f1a5..fa7abe9471 100644
--- a/order/templates/order/address.html
+++ b/order/templates/order/address.html
@@ -1,12 +1,22 @@
{% extends "base.html" %}
+{% load as_bootstrap from bootstrap %}
+
{% block content %}
-<form action="." method="post">
+<form action="." method="post" class="form-horizontal">
{% csrf_token %}
- {{ managment_form }}
- {{ address_list_form }}
- {{ address_form }}
+ {{ managment_form|as_bootstrap }}
+ {% if user.is_authenticated %}
+ <fieldset>
+ <legend>Select address:</legend>
+ {{ address_list_form|as_bootstrap }}
+ </fieldset>
+ {% endif %}
+ <fieldset>
+ <legend>Complete address:</legend>
+ {{ address_form|as_bootstrap }}
+ </fieldset>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
diff --git a/order/views.py b/order/views.py
index cff12a1b5a..16f33e60e1 100644
--- a/order/views.py
+++ b/order/views.py
@@ -10,7 +10,8 @@ class BillingFormManager(object):
method = None
def __init__(self, request):
- self.managment_form = ManagementForm(request.POST or None)
+ self.managment_form = ManagementForm(request.user.is_authenticated(),
+ request.POST or None)
self.address_list_form = UserAddressesForm(user=request.user)
self.address_form = AddressForm()
@@ -48,7 +49,6 @@ def billing_address(request):
if manager.is_valid():
print manager.cleaned_data
-
return TemplateResponse(request, 'order/address.html', {
'order': order,
'managment_form': manager.managment_form,