From 0cd8fd5b1129a39375a1391287f4cca01e6fa28b Mon Sep 17 00:00:00 2001 From: AmirHossein Bonakdar Date: Mon, 13 Sep 2021 19:32:01 +0430 Subject: [PATCH 01/10] Update(sanppfood/urls): include order urls --- snapp_food/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/snapp_food/urls.py b/snapp_food/urls.py index 0e6e7e0..b36d68f 100644 --- a/snapp_food/urls.py +++ b/snapp_food/urls.py @@ -28,6 +28,7 @@ path('item/', include('item.urls', namespace='item')), path('cart/', include('cart.urls', namespace='cart')), path('payment/', include('payment.urls', namespace='payment')), + path('order/', include('order.urls', namespace='order')), ] From 74c0006ff33a99472f1f9e7cd9ef2231c1806020 Mon Sep 17 00:00:00 2001 From: AmirHossein Bonakdar Date: Mon, 13 Sep 2021 19:32:35 +0430 Subject: [PATCH 02/10] Add(order/urls): add urlpatterns to urls.py --- order/urls.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 order/urls.py diff --git a/order/urls.py b/order/urls.py new file mode 100644 index 0000000..388aeb3 --- /dev/null +++ b/order/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from order.views import CustomerOrdersListView, CustomerOrderDetailView + +app_name = 'order' + +urlpatterns = [ + path('customer/list/', CustomerOrdersListView.as_view(), name='customer-list'), + path('customer//detail/', CustomerOrderDetailView.as_view(), name='customer-detail'), +] \ No newline at end of file From 99c2c63dba21ebcf2db6df58c313bd87aa723f7a Mon Sep 17 00:00:00 2001 From: AmirHossein Bonakdar Date: Mon, 13 Sep 2021 19:33:16 +0430 Subject: [PATCH 03/10] Add(order/views): create CustomerOrderDetailView --- order/views.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/order/views.py b/order/views.py index 91ea44a..c55c725 100644 --- a/order/views.py +++ b/order/views.py @@ -1,3 +1,37 @@ -from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from django.urls import reverse_lazy +from django.utils.decorators import method_decorator +from django.views.decorators.http import require_http_methods +from django.views.generic import ListView, DetailView + +from accounts.models import Customer +from accounts.utils import IsCustomer +from library.utils import CustomUserPasses +from order.models import Order + + +@method_decorator(require_http_methods(['GET']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:customer-login-register')), name='dispatch') +class CustomerOrdersListView(IsCustomer, ListView): + template_name = 'order/customer/order_list.html' + context_object_name = 'orders' + + def get_queryset(self): + return Order.objects.select_related('invoice__cart').filter(customer=self.request.user) + + +@method_decorator(require_http_methods(['GET']), name='dispatch') +@method_decorator(login_required(login_url=reverse_lazy('accounts:customer-login-register')), name='dispatch') +class CustomerOrderDetailView(CustomUserPasses, DetailView): + model = Order + template_name = 'order/customer/order_detail.html' + context_object_name = 'order' + + def test_func(self): + user = self.request.user + if not isinstance(user, Customer): + return False + if self.get_object().customer != self.request.user: + return False + return True -# Create your views here. From b7e503c169c5f2296da6b499f1927264815e7755 Mon Sep 17 00:00:00 2001 From: AmirHossein Bonakdar Date: Mon, 13 Sep 2021 19:35:05 +0430 Subject: [PATCH 04/10] add order_list and order_detail for customers --- .../order/customer/order_detail.html | 34 +++++++++++++++++++ .../templates/order/customer/order_list.html | 21 ++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 order/templates/order/customer/order_detail.html create mode 100644 order/templates/order/customer/order_list.html diff --git a/order/templates/order/customer/order_detail.html b/order/templates/order/customer/order_detail.html new file mode 100644 index 0000000..1922b94 --- /dev/null +++ b/order/templates/order/customer/order_detail.html @@ -0,0 +1,34 @@ +{% extends 'base.html' %} +{% block title %} Order Detail {% endblock %} + +{% block content %} +

{{ order.invoice.cart.service }}

+

+

status : {{ order.get_status_display }}

+

order date time : {{ order.created_time }}

+

address : {{ order.invoice.address }}

+

+ + + + + + + + + + + {% for line in order.invoice.cart.lines.all %} + + + + + + {% endfor %} + + +
ItemQuantityPrice
{{ line.item }}{{ line.quantity }}$ {{ line.price }}
+ +
Total price : {{ order.invoice.price }}
+ +{% endblock %} \ No newline at end of file diff --git a/order/templates/order/customer/order_list.html b/order/templates/order/customer/order_list.html new file mode 100644 index 0000000..7aaf000 --- /dev/null +++ b/order/templates/order/customer/order_list.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} +{% block title %} Orders {% endblock %} + +{% block content %} +

Your orders

+ +{% endblock %} \ No newline at end of file From 882cc167c1619cdd567bff6e73e539540a5ee252 Mon Sep 17 00:00:00 2001 From: AmirHossein Bonakdar Date: Mon, 13 Sep 2021 19:35:51 +0430 Subject: [PATCH 05/10] Update(templates/inc): add orders link in navbar --- templates/inc/customer_navbar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/inc/customer_navbar.html b/templates/inc/customer_navbar.html index 985bc67..62a0bc3 100644 --- a/templates/inc/customer_navbar.html +++ b/templates/inc/customer_navbar.html @@ -12,7 +12,7 @@ Profile