From e75f1dc1bcc3bc736ac2b346d118c8b891528244 Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Sun, 16 Jul 2023 12:42:58 -0600 Subject: [PATCH] Finish address template changes --- accounts/forms.py | 16 ++++++++++- .../templates/dashboard/customer/detail.html | 6 ++--- .../templates/dashboard/order/detail.html | 2 +- .../dashboard/order/tracking_form.html | 2 +- .../dashboard/partials/_address.html | 7 ++--- static/styles/main.css | 15 +++++++++++ storefront/cart.py | 8 +++--- .../templates/storefront/customer_detail.html | 21 +++++++-------- .../templates/storefront/customer_form.html | 19 ++++++++----- .../customer_shipping_address_form.html | 27 +++++++++++++++++++ storefront/urls.py | 5 ++++ storefront/views.py | 20 +++++++++++++- templates/account/password_change.html | 16 +++++++++-- 13 files changed, 130 insertions(+), 34 deletions(-) create mode 100644 storefront/templates/storefront/customer_shipping_address_form.html diff --git a/accounts/forms.py b/accounts/forms.py index 9762acc..a61a599 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -27,18 +27,32 @@ class AccountUpdateForm(UserChangeForm): class CustomerUpdateForm(forms.ModelForm): + class Meta: + model = User + fields = ( + 'email', + ) + + +class CustomerShippingAddressUpdateForm(forms.ModelForm): class Meta: model = User fields = ( 'first_name', 'last_name', - 'email', 'shipping_street_address_1', 'shipping_street_address_2', 'shipping_city', 'shipping_state', 'shipping_postal_code', ) + labels = { + 'shipping_street_address_1': 'Street line 1', + 'shipping_street_address_2': 'Street line 2', + 'shipping_city': 'City', + 'shipping_state': 'State', + 'shipping_postal_code': 'ZIP code', + } class UserSignupForm(SignupForm): diff --git a/dashboard/templates/dashboard/customer/detail.html b/dashboard/templates/dashboard/customer/detail.html index fe2a932..4edbad1 100644 --- a/dashboard/templates/dashboard/customer/detail.html +++ b/dashboard/templates/dashboard/customer/detail.html @@ -19,14 +19,14 @@

Details

-
Primary email address
+
Email address
{{ customer.email }} ↗
-
Default shipping address
+
Shipping address
- {% include 'dashboard/partials/_address.html' with address=customer %} + {% include 'dashboard/partials/_address.html' with full_name=customer.get_full_name address=customer %}
diff --git a/dashboard/templates/dashboard/order/detail.html b/dashboard/templates/dashboard/order/detail.html index 4709e1e..b95f6a9 100644 --- a/dashboard/templates/dashboard/order/detail.html +++ b/dashboard/templates/dashboard/order/detail.html @@ -133,7 +133,7 @@
Shipping address - {% include 'dashboard/partials/_address.html' with address=order %} + {% include 'dashboard/partials/_address.html' with full_name=order.customer.get_full_name address=order %}
diff --git a/dashboard/templates/dashboard/order/tracking_form.html b/dashboard/templates/dashboard/order/tracking_form.html index f8d45b3..33fa38e 100644 --- a/dashboard/templates/dashboard/order/tracking_form.html +++ b/dashboard/templates/dashboard/order/tracking_form.html @@ -17,7 +17,7 @@
Shipping address - {% include 'dashboard/partials/_address.html' with address=order %} + {% include 'dashboard/partials/_address.html' with full_name=order.customer.get_full_name address=order %}
{% csrf_token %} diff --git a/dashboard/templates/dashboard/partials/_address.html b/dashboard/templates/dashboard/partials/_address.html index 7c3de9e..707ae64 100644 --- a/dashboard/templates/dashboard/partials/_address.html +++ b/dashboard/templates/dashboard/partials/_address.html @@ -1,7 +1,8 @@
- {{address.shipping_street_address_1}}
+ {{ full_name }}
+ {{ address.shipping_street_address_1 }}
{% if address.shipping_street_address_2 %} - {{address.shipping_street_address_2}}
+ {{ address.shipping_street_address_2 }}
{% endif %} - {{address.shipping_city}}, {{address.shipping_state}}, {{address.shipping_postal_code}} + {{ address.shipping_city }}, {{ address.shipping_state }}, {{ address.shipping_postal_code }}
diff --git a/static/styles/main.css b/static/styles/main.css index a098f1a..7406904 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -126,6 +126,21 @@ table a { white-space: normal; } +.form-table { + width: unset; + border: none; +} +.form-table th, +.form-table td { + border: none; +} +.form-table th { + padding: 0 1rem 1rem 0; +} +.form-table td { + padding: 0 0 1rem 0; +} + /* ========================================================================== Forms diff --git a/storefront/cart.py b/storefront/cart.py index 32cfb90..d4cbb40 100644 --- a/storefront/cart.py +++ b/storefront/cart.py @@ -255,7 +255,7 @@ class Cart: if container is None: container = self.get_shipping_container() - if not self.total_weight > Weight(lb=0): + if self.total_weight <= Weight(lb=0): return Decimal('0.00') if len(self) > 0 and self.session.get('shipping_address'): @@ -286,11 +286,11 @@ class Cart: ) if usps_rate_request['service'] == ShippingContainer.PRIORITY: - shipping_cost = Decimal(postage['Rate']) + shipping_price = Decimal(postage['Rate']) elif usps_rate_request['service'] == ShippingContainer.PRIORITY_COMMERCIAL: - shipping_cost = Decimal(postage['CommercialRate']) + shipping_price = Decimal(postage['CommercialRate']) - return shipping_cost + return shipping_price else: raise ShippingAddressError( 'Could not retrieve shipping address.' diff --git a/storefront/templates/storefront/customer_detail.html b/storefront/templates/storefront/customer_detail.html index 5bdc0b4..c31dfa4 100644 --- a/storefront/templates/storefront/customer_detail.html +++ b/storefront/templates/storefront/customer_detail.html @@ -5,21 +5,20 @@ {% block content %}
-
-

{{customer.get_full_name}}

- Edit profile -
-

Info

+

My Account

+

+ Change password +

- Email address
- {{customer.email}}
- Manage + Email address Change
+ {{customer.email}}
- Shipping address + Shipping address Change
+ {{ customer.get_full_name }}
{{customer.shipping_street_address_1}}
{% if shipping_street_address_2 %} {{customer.shipping_street_address_2}}
@@ -31,7 +30,7 @@
{% if customer.subscriptions.count > 0 %}
-

Your subscriptions

+

My subscriptions

@@ -53,7 +52,7 @@ {% endif %}
-

Your orders

+

My orders

diff --git a/storefront/templates/storefront/customer_form.html b/storefront/templates/storefront/customer_form.html index b63ba12..a7d7911 100644 --- a/storefront/templates/storefront/customer_form.html +++ b/storefront/templates/storefront/customer_form.html @@ -5,17 +5,22 @@

← Back

Update your profile

-

- Change password -

{% csrf_token %} - {{form.as_p}} -

- -

+
+ {{form.as_table}} + + + + + + +
+ + +
diff --git a/storefront/templates/storefront/customer_shipping_address_form.html b/storefront/templates/storefront/customer_shipping_address_form.html new file mode 100644 index 0000000..9f8c336 --- /dev/null +++ b/storefront/templates/storefront/customer_shipping_address_form.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} + +{% block content %} +
+
+

← Back

+

Update your shipping address

+
+
+
+ {% csrf_token %} + + {{form.as_table}} + + + + + + +
+ + +
+
+
+
+{% endblock %} diff --git a/storefront/urls.py b/storefront/urls.py index 920d2a4..bf34d62 100644 --- a/storefront/urls.py +++ b/storefront/urls.py @@ -89,6 +89,11 @@ urlpatterns = [ views.CustomerUpdateView.as_view(), name='customer-update', ), + path( + 'shipping-address/update/', + views.CustomerShippingAddressUpdateView.as_view(), + name='customer-shipping-address-update', + ), path( 'orders//', views.OrderDetailView.as_view(), diff --git a/storefront/views.py b/storefront/views.py index 5bb02e2..cd541c3 100644 --- a/storefront/views.py +++ b/storefront/views.py @@ -36,7 +36,7 @@ from moneyed import Money, USD from accounts.models import User from accounts.utils import get_or_create_customer -from accounts.forms import CustomerUpdateForm +from accounts.forms import CustomerUpdateForm, CustomerShippingAddressUpdateForm from core.models import ( ProductCategory, Product, ProductVariant, ProductOption, Order, Transaction, OrderLine, Coupon, ShippingRate, @@ -557,6 +557,24 @@ class CustomerUpdateView(UserPassesTestMixin, LoginRequiredMixin, UpdateView): ) +class CustomerShippingAddressUpdateView(UserPassesTestMixin, LoginRequiredMixin, UpdateView): + model = User + template_name = 'storefront/customer_shipping_address_form.html' + context_object_name = 'customer' + form_class = CustomerShippingAddressUpdateForm + permission_denied_message = 'Not authorized.' + raise_exception = True + + def test_func(self): + return self.request.user.pk == self.get_object().pk + + def get_success_url(self): + return reverse( + 'storefront:customer-detail', kwargs={'pk': self.object.pk} + ) + + + class OrderDetailView(UserPassesTestMixin, LoginRequiredMixin, DetailView): model = Order template_name = 'storefront/order_detail.html' diff --git a/templates/account/password_change.html b/templates/account/password_change.html index 466b1fd..0a23b3a 100644 --- a/templates/account/password_change.html +++ b/templates/account/password_change.html @@ -14,8 +14,20 @@
{% csrf_token %} - {{ form.as_p }} - + + + {{ form.as_table }} + + + + + + + +
+ + +
{% endblock %}