Finish address template changes

This commit is contained in:
Nathan Chapman 2023-07-16 12:42:58 -06:00
parent cf4a1e5ec7
commit e75f1dc1bc
13 changed files with 130 additions and 34 deletions

View File

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

View File

@ -19,14 +19,14 @@
<h4>Details</h4>
</header>
<dl class="panel-datalist">
<dt>Primary email address</dt>
<dt>Email address</dt>
<dd>
<a href="mailto:{{ customer.email }}">{{ customer.email }} &nearr;</a>
</dd>
<dt>Default shipping address</dt>
<dt>Shipping address</dt>
<dd>
{% include 'dashboard/partials/_address.html' with address=customer %}
{% include 'dashboard/partials/_address.html' with full_name=customer.get_full_name address=customer %}
</dd>
</dl>
</section>

View File

@ -133,7 +133,7 @@
<div class="panel-section panel-shipping">
<div>
<strong>Shipping address</strong>
{% include 'dashboard/partials/_address.html' with address=order %}
{% include 'dashboard/partials/_address.html' with full_name=order.customer.get_full_name address=order %}
</div>
<table>
<thead>

View File

@ -17,7 +17,7 @@
</header>
<div class="panel-section">
<strong>Shipping address</strong>
{% include 'dashboard/partials/_address.html' with address=order %}
{% include 'dashboard/partials/_address.html' with full_name=order.customer.get_full_name address=order %}
</div>
<form method="POST">
{% csrf_token %}

View File

@ -1,4 +1,5 @@
<address>
{{ full_name }}<br>
{{ address.shipping_street_address_1 }}<br>
{% if address.shipping_street_address_2 %}
{{ address.shipping_street_address_2 }}<br>

View File

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

View File

@ -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.'

View File

@ -5,21 +5,20 @@
{% block content %}
<article>
<header class="article__header--with-action">
<h1>{{customer.get_full_name}}</h1>
<a href="{% url 'storefront:customer-update' customer.pk %}" class="btn">Edit profile</a>
</header>
<section>
<h4>Info</h4>
<h2>My Account</h2>
<p>
<a href="{% url 'account_change_password' %}">Change password</a>
</p>
<div class="customer__detail-section">
<div>
<strong>Email address</strong><br>
{{customer.email}}<br>
<a href="{% url 'account_email' %}">Manage</a>
<strong>Email address</strong> <a href="{% url 'storefront:customer-update' customer.pk %}">Change</a><br>
{{customer.email}}
</div>
<div>
<strong>Shipping address</strong>
<strong>Shipping address</strong> <a href="{% url 'storefront:customer-shipping-address-update' customer.pk %}">Change</a>
<address>
{{ customer.get_full_name }}<br>
{{customer.shipping_street_address_1}}<br>
{% if shipping_street_address_2 %}
{{customer.shipping_street_address_2}}<br>
@ -31,7 +30,7 @@
</section>
{% if customer.subscriptions.count > 0 %}
<section>
<h3>Your subscriptions</h3>
<h3>My subscriptions</h3>
<table>
<thead>
<tr>
@ -53,7 +52,7 @@
</section>
{% endif %}
<section>
<h3>Your orders</h3>
<h3>My orders</h3>
<table>
<thead>
<tr>

View File

@ -5,17 +5,22 @@
<header>
<p><a href="{% url 'storefront:customer-detail' customer.pk %}">&larr; Back</a></p>
<h1>Update your profile</h1>
<p>
<a href="{% url 'account_change_password' %}">Change password</a>
</p>
</header>
<section>
<form method="POST" action="{% url 'storefront:customer-update' customer.pk %}">
{% csrf_token %}
{{form.as_p}}
<p>
<input type="submit" value="Save changes">
</p>
<table class="form-table">
{{form.as_table}}
<tfoot>
<tr>
<td>
</td>
<td>
<button type="submit">Save changes</button>
</td>
</tr>
</tfoot>
</table>
</form>
</section>
</article>

View File

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block content %}
<article>
<header>
<p><a href="{% url 'storefront:customer-detail' customer.pk %}">&larr; Back</a></p>
<h1>Update your shipping address</h1>
</header>
<section>
<form method="POST">
{% csrf_token %}
<table class="form-table">
{{form.as_table}}
<tfoot>
<tr>
<td>
</td>
<td>
<button type="submit">Save changes</button>
</td>
</tr>
</tfoot>
</table>
</form>
</section>
</article>
{% endblock %}

View File

@ -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/<int:order_pk>/',
views.OrderDetailView.as_view(),

View File

@ -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'

View File

@ -14,8 +14,20 @@
<form method="POST" action="{% url 'account_change_password' %}" class="password_change">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans "Save changes" %}">
<table class="form-table">
<tbody>
{{ form.as_table }}
</tbody>
<tfoot>
<tr>
<td>
</td>
<td>
<button type="submit">Save changes</button>
</td>
</tr>
</tfoot>
</table>
</form>
</article>
{% endblock %}