diff --git a/counter/templates/counter/product_list.jinja b/counter/templates/counter/product_list.jinja index da815c09..959d6797 100644 --- a/counter/templates/counter/product_list.jinja +++ b/counter/templates/counter/product_list.jinja @@ -8,25 +8,17 @@ {% if current_tab == "products" %}

{% trans %}New product{% endtrans %}

{% endif %} - {% if product_list %} -

{% trans %}Product list{% endtrans %}

- {% for t in ProductType.objects.all().order_by('name') %} -

{{ t }}

- - {% endfor %} -

{% trans %}Uncategorized{% endtrans %}

+

{% trans %}Product list{% endtrans %}

+ {%- for product_type, products in object_list -%} +

{{ product_type or _("Uncategorized") }}

- {% else %} + {%- else -%} {% trans %}There is no products in this website.{% endtrans %} - {% endif %} + {%- endfor -%} {% endblock %} diff --git a/counter/urls.py b/counter/urls.py index bf8eba2c..4dd12517 100644 --- a/counter/urls.py +++ b/counter/urls.py @@ -19,11 +19,7 @@ from counter.views import * urlpatterns = [ path("/", CounterMain.as_view(), name="details"), - path( - "/click//", - CounterClick.as_view(), - name="click", - ), + path("/click//", CounterClick.as_view(), name="click"), path( "/last_ops/", CounterLastOperationsView.as_view(), @@ -34,19 +30,11 @@ urlpatterns = [ CounterCashSummaryView.as_view(), name="cash_summary", ), - path( - "/activity/", - CounterActivityView.as_view(), - name="activity", - ), + path("/activity/", CounterActivityView.as_view(), name="activity"), path("/stats/", CounterStatView.as_view(), name="stats"), path("/login/", counter_login, name="login"), path("/logout/", counter_logout, name="logout"), - path( - "eticket//pdf/", - EticketPDFView.as_view(), - name="eticket_pdf", - ), + path("eticket//pdf/", EticketPDFView.as_view(), name="eticket_pdf"), path( "customer//card/add/", StudentCardFormView.as_view(), @@ -59,17 +47,11 @@ urlpatterns = [ ), path("admin//", CounterEditView.as_view(), name="admin"), path( - "admin//prop/", - CounterEditPropView.as_view(), - name="prop_admin", + "admin//prop/", CounterEditPropView.as_view(), name="prop_admin" ), path("admin/", CounterListView.as_view(), name="admin_list"), path("admin/new/", CounterCreateView.as_view(), name="new"), - path( - "admin/delete//", - CounterDeleteView.as_view(), - name="delete", - ), + path("admin/delete//", CounterDeleteView.as_view(), name="delete"), path("admin/invoices_call/", InvoiceCallView.as_view(), name="invoices_call"), path( "admin/cash_summary/list/", @@ -81,10 +63,10 @@ urlpatterns = [ CashSummaryEditView.as_view(), name="cash_summary_edit", ), - path("admin/product/list/", ProductListView.as_view(), name="product_list"), + path("admin/product/list/", ActiveProductListView.as_view(), name="product_list"), path( "admin/product/list_archived/", - ProductArchivedListView.as_view(), + ArchivedProductListView.as_view(), name="product_list_archived", ), path("admin/product/create/", ProductCreateView.as_view(), name="new_product"), diff --git a/counter/views.py b/counter/views.py index e5a64bf1..56546818 100644 --- a/counter/views.py +++ b/counter/views.py @@ -12,10 +12,12 @@ # OR WITHIN THE LOCAL FILE "LICENSE" # # +import itertools import re from datetime import datetime, timedelta from datetime import timezone as tz from http import HTTPStatus +from operator import attrgetter from typing import TYPE_CHECKING from urllib.parse import parse_qs @@ -804,25 +806,41 @@ class ProductTypeEditView(CounterAdminTabsMixin, CounterAdminMixin, UpdateView): current_tab = "products" -class ProductArchivedListView(CounterAdminTabsMixin, CounterAdminMixin, ListView): +class ProductListView(CounterAdminTabsMixin, CounterAdminMixin, ListView): + model = Product + queryset = Product.objects.annotate(type_name=F("product_type__name")) + template_name = "counter/product_list.jinja" + ordering = [ + F("product_type__priority").desc(nulls_last=True), + "product_type", + "name", + ] + + def get_context_data(self, **kwargs): + res = super().get_context_data(**kwargs) + res["object_list"] = itertools.groupby( + res["object_list"], key=attrgetter("type_name") + ) + return res + + +class ArchivedProductListView(ProductListView): """A list view for the admins.""" - model = Product - template_name = "counter/product_list.jinja" - queryset = Product.objects.filter(archived=True) - ordering = ["name"] current_tab = "archive" + def get_queryset(self): + return super().get_queryset().filter(archived=True) -class ProductListView(CounterAdminTabsMixin, CounterAdminMixin, ListView): + +class ActiveProductListView(ProductListView): """A list view for the admins.""" - model = Product - template_name = "counter/product_list.jinja" - queryset = Product.objects.filter(archived=False) - ordering = ["name"] current_tab = "products" + def get_queryset(self): + return super().get_queryset().filter(archived=False) + class ProductCreateView(CounterAdminTabsMixin, CounterAdminMixin, CreateView): """A create view for the admins."""