From e2ef635abc0d8ae1baed67dada6228dfa8e53f1d Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Wed, 1 Aug 2018 11:33:36 +0200 Subject: [PATCH 1/3] overwrite get_queryset on ProductHandoutView and delete unused imports --- src/backoffice/views.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/backoffice/views.py b/src/backoffice/views.py index 7f057728..2a9039dc 100644 --- a/src/backoffice/views.py +++ b/src/backoffice/views.py @@ -5,14 +5,11 @@ from django.views.generic import TemplateView, ListView from django.views.generic.edit import UpdateView from django.shortcuts import redirect from django.urls import reverse -from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib import messages from shop.models import OrderProductRelation from tickets.models import ShopTicket, SponsorTicket, DiscountTicket from profiles.models import Profile -from camps.models import Camp -from camps.mixins import CampViewMixin from program.models import SpeakerProposal, EventProposal from .mixins import BackofficeViewMixin @@ -26,12 +23,14 @@ class BackofficeIndexView(BackofficeViewMixin, TemplateView): class ProductHandoutView(BackofficeViewMixin, ListView): template_name = "product_handout.html" - queryset = OrderProductRelation.objects.filter( - handed_out=False, - order__paid=True, - order__refunded=False, - order__cancelled=False - ).order_by('order') + + def get_queryset(self, **kwargs): + return OrderProductRelation.objects.filter( + handed_out=False, + order__paid=True, + order__refunded=False, + order__cancelled=False + ).order_by('order') class BadgeHandoutView(BackofficeViewMixin, ListView): From e04038e4a0266c312eb68a3f09bc39b5e404594a Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Wed, 1 Aug 2018 11:50:16 +0200 Subject: [PATCH 2/3] add backoffice pages for merchandise orders and what merchandise to order --- src/backoffice/templates/index.html | 8 +++ .../templates/merchandise_to_order.html | 44 ++++++++++++++++ .../templates/orders_merchandise.html | 51 +++++++++++++++++++ src/backoffice/urls.py | 2 + src/backoffice/views.py | 46 +++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100644 src/backoffice/templates/merchandise_to_order.html create mode 100644 src/backoffice/templates/orders_merchandise.html diff --git a/src/backoffice/templates/index.html b/src/backoffice/templates/index.html index bc9710cc..c121fe43 100644 --- a/src/backoffice/templates/index.html +++ b/src/backoffice/templates/index.html @@ -34,6 +34,14 @@

Manage Proposals

Use this view to manage SpeakerProposals and EventProposals

+ +

Merchandise Orders

+

Use this view to look at Merchandise Orders

+
+ +

Merchandise To Order

+

Use this view to generate a list of merchandise that needs to be ordered

+
diff --git a/src/backoffice/templates/merchandise_to_order.html b/src/backoffice/templates/merchandise_to_order.html new file mode 100644 index 00000000..bbf6a6b2 --- /dev/null +++ b/src/backoffice/templates/merchandise_to_order.html @@ -0,0 +1,44 @@ +{% extends 'base.html' %} +{% load commonmark %} +{% load static from staticfiles %} +{% load imageutils %} +{% block extra_head %} + + +{% endblock extra_head %} +{% block content %} +
+

Merchandise To Order

+
+ This is a list of merchandise to order from our supplier +
+
+ This table shows all different merchandise that needs to be ordered +
+
+
+
+ + + + + + + + + {% for key, val in merchandise.items %} + + + + + {% endfor %} + +
Merchandise TypeQuantity
{{ key }}{{ val }}
+
+ + +{% endblock content %} diff --git a/src/backoffice/templates/orders_merchandise.html b/src/backoffice/templates/orders_merchandise.html new file mode 100644 index 00000000..dcaf94be --- /dev/null +++ b/src/backoffice/templates/orders_merchandise.html @@ -0,0 +1,51 @@ +{% extends 'base.html' %} +{% load commonmark %} +{% load static from staticfiles %} +{% load imageutils %} +{% block extra_head %} + + +{% endblock extra_head %} +{% block content %} +
+

Merchandise Orders

+
+ Use this view to look at merchandise orders.
+
+ This table shows all OrderProductRelations which are Merchandise (not including handed out, unpaid, cancelled and refunded orders). The table is initally sorted by order ID but the sorting can be changed by clicking the column headlines (if javascript is enabled). +
+
+
+
+ + + + + + + + + + + + + {% for productrel in orderproductrelation_list %} + + + + + + + + + {% endfor %} + +
OrderUserEmailOPR IdProductQuantity
Order #{{ productrel.order.id }}{{ productrel.order.user }}{{ productrel.order.user.email }}{{ productrel.id }}{{ productrel.product.name }}{{ productrel.quantity }}
+
+ + +{% endblock content %} diff --git a/src/backoffice/urls.py b/src/backoffice/urls.py index 58da109d..f48cced5 100644 --- a/src/backoffice/urls.py +++ b/src/backoffice/urls.py @@ -10,6 +10,8 @@ urlpatterns = [ path('badge_handout/', BadgeHandoutView.as_view(), name='badge_handout'), path('ticket_checkin/', TicketCheckinView.as_view(), name='ticket_checkin'), path('public_credit_names/', ApproveNamesView.as_view(), name='public_credit_names'), + path('merchandise_orders/', MerchandiseOrdersView.as_view(), name='merchandise_orders'), + path('merchandise_to_order/', MerchandiseToOrderView.as_view(), name='merchandise_to_order'), path('manage_proposals/', include([ path('', ManageProposalsView.as_view(), name='manage_proposals'), path('speakers//', SpeakerProposalManageView.as_view(), name='speakerproposal_manage'), diff --git a/src/backoffice/views.py b/src/backoffice/views.py index 2a9039dc..d0a83d53 100644 --- a/src/backoffice/views.py +++ b/src/backoffice/views.py @@ -1,5 +1,6 @@ import logging from itertools import chain +from datetime import datetime from django.views.generic import TemplateView, ListView from django.views.generic.edit import UpdateView @@ -122,3 +123,48 @@ class EventProposalManageView(ProposalManageView): model = EventProposal template_name = "manage_eventproposal.html" + +class MerchandiseOrdersView(BackofficeViewMixin, ListView): + template_name = "orders_merchandise.html" + + def get_queryset(self, **kwargs): + camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y')) + + return OrderProductRelation.objects.filter( + handed_out=False, + order__paid=True, + order__refunded=False, + order__cancelled=False, + product__category__name='Merchandise', + ).filter( + product__name__startswith=camp_prefix + ).order_by('order') + + +class MerchandiseToOrderView(BackofficeViewMixin, TemplateView): + template_name = "merchandise_to_order.html" + + def get_context_data(self, **kwargs): + camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y')) + + order_relations = OrderProductRelation.objects.filter( + handed_out=False, + order__paid=True, + order__refunded=False, + order__cancelled=False, + product__category__name='Merchandise', + ).filter( + product__name__startswith=camp_prefix + ) + + merchandise_orders = {} + for relation in order_relations: + try: + quantity = merchandise_orders[relation.product.name] + relation.quantity + merchandise_orders[relation.product.name] = quantity + except KeyError: + merchandise_orders[relation.product.name] = relation.quantity + + context = super().get_context_data(**kwargs) + context['merchandise'] = merchandise_orders + return context From d03af1c11e8338e80d122f48a4f4995846f626cc Mon Sep 17 00:00:00 2001 From: Stephan Telling Date: Wed, 1 Aug 2018 12:25:43 +0200 Subject: [PATCH 3/3] use django.utils timezone rather than datetime --- src/backoffice/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backoffice/views.py b/src/backoffice/views.py index d0a83d53..06af7073 100644 --- a/src/backoffice/views.py +++ b/src/backoffice/views.py @@ -1,12 +1,12 @@ import logging from itertools import chain -from datetime import datetime from django.views.generic import TemplateView, ListView from django.views.generic.edit import UpdateView from django.shortcuts import redirect from django.urls import reverse from django.contrib import messages +from django.utils import timezone from shop.models import OrderProductRelation from tickets.models import ShopTicket, SponsorTicket, DiscountTicket @@ -128,7 +128,7 @@ class MerchandiseOrdersView(BackofficeViewMixin, ListView): template_name = "orders_merchandise.html" def get_queryset(self, **kwargs): - camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y')) + camp_prefix = 'BornHack {}'.format(timezone.now().year) return OrderProductRelation.objects.filter( handed_out=False, @@ -145,7 +145,7 @@ class MerchandiseToOrderView(BackofficeViewMixin, TemplateView): template_name = "merchandise_to_order.html" def get_context_data(self, **kwargs): - camp_prefix = 'BornHack {}'.format(datetime.now().strftime('%Y')) + camp_prefix = 'BornHack {}'.format(timezone.now().year) order_relations = OrderProductRelation.objects.filter( handed_out=False,