From 332840aa3bffa2ec16224eca040c3abcd880aeeb Mon Sep 17 00:00:00 2001 From: Nathan Chapman Date: Thu, 19 May 2022 19:16:41 -0600 Subject: [PATCH] Proper order filtering for customer view --- src/core/models.py | 5 +++++ src/static/styles/main.css | 16 +++++++++++++++- .../templates/storefront/customer_detail.html | 4 +--- .../templates/storefront/order_detail.html | 4 ++++ src/storefront/views.py | 7 +++++++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/core/models.py b/src/core/models.py index 1c86e8c..59c8e2f 100644 --- a/src/core/models.py +++ b/src/core/models.py @@ -165,6 +165,11 @@ class OrderManager(models.Manager): def with_lines(self): return self.select_related('lines') + def without_drafts(self): + return self.exclude( + status=OrderStatus.DRAFT + ) + def with_fulfillment(self): return self.annotate( total_quantity_fulfilled=models.Sum('lines__quantity_fulfilled'), diff --git a/src/static/styles/main.css b/src/static/styles/main.css index 7cfbe56..44ac42b 100644 --- a/src/static/styles/main.css +++ b/src/static/styles/main.css @@ -577,13 +577,20 @@ article > header { display: flex; justify-content: space-between; align-items: center; - align-content: center; } .article__header--with-action h1 { margin-bottom: 0; } +@media screen and (max-width: 600px) { + .article__header--with-action { + flex-direction: column; + align-items: flex-start; + } + +} + article + article { margin-top: 8rem; } @@ -897,6 +904,13 @@ article + article { gap: 4rem; } +@media screen and (max-width: 600px) { + .customer__detail-section { + grid-template-columns: 1fr; + gap: 1rem; + } +} + diff --git a/src/storefront/templates/storefront/customer_detail.html b/src/storefront/templates/storefront/customer_detail.html index e833612..213666d 100644 --- a/src/storefront/templates/storefront/customer_detail.html +++ b/src/storefront/templates/storefront/customer_detail.html @@ -57,7 +57,6 @@ {% endfor %} -{% with order_list=customer.orders.all %}

Your orders

@@ -73,7 +72,7 @@ - + {% empty %} @@ -82,6 +81,5 @@
#{{order.pk}} {{order.created_at|date:"M j, Y"}}${{order.total_net_amount}}${{order.get_total_price_after_discount}} See details →
-{% endwith %} {% endblock content %} diff --git a/src/storefront/templates/storefront/order_detail.html b/src/storefront/templates/storefront/order_detail.html index 629d452..7c0d48c 100644 --- a/src/storefront/templates/storefront/order_detail.html +++ b/src/storefront/templates/storefront/order_detail.html @@ -56,6 +56,10 @@ {{order.coupon.discount_value}} {{order.coupon.get_discount_value_type_display}} {% endif %} + + Shipping + ${{order.shipping_total}} + Total ${{order.get_total_price_after_discount}} diff --git a/src/storefront/views.py b/src/storefront/views.py index fda99d2..62aba88 100644 --- a/src/storefront/views.py +++ b/src/storefront/views.py @@ -337,6 +337,13 @@ class CustomerDetailView(UserPassesTestMixin, LoginRequiredMixin, DetailView): permission_denied_message = 'Not authorized.' raise_exception = True + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + context['order_list'] = Order.objects.without_drafts().filter( + customer=self.object + ).prefetch_related('lines') + return context + def test_func(self): return self.request.user.pk == self.get_object().pk