From 725e5fa5f311b8681c3dacb6ad638b11f1d60871 Mon Sep 17 00:00:00 2001 From: bpc Date: Wed, 13 Nov 2024 23:21:08 +0100 Subject: [PATCH] Add extra dropdowns for every year in payment history --- .../payments/templates/payments/payment_list.html | 9 ++++++--- website/payments/views.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/website/payments/templates/payments/payment_list.html b/website/payments/templates/payments/payment_list.html index fc4f860fb..eabab2fbb 100644 --- a/website/payments/templates/payments/payment_list.html +++ b/website/payments/templates/payments/payment_list.html @@ -16,7 +16,7 @@
{% endif %} {% if object_list %} diff --git a/website/payments/views.py b/website/payments/views.py index 577c9c560..ef0d3a855 100644 --- a/website/payments/views.py +++ b/website/payments/views.py @@ -1,4 +1,5 @@ from decimal import Decimal +from itertools import groupby from django.apps import apps from django.conf import settings @@ -145,14 +146,21 @@ def get_queryset(self) -> QuerySet: def get_context_data(self, *args, **kwargs): filters = [] - for i in range(13): + + for i in range(85): new_now = timezone.now() - relativedelta(months=i) filters.append({"year": new_now.year, "month": new_now.month}) + + initial_filters = filters[:6] + year_filters = [] + for key, group in groupby(filters[6:], lambda f: f["year"]): + year_filters.append({"year": key, "months": list(group)}) context = super().get_context_data(*args, **kwargs) context.update( { - "filters": filters, + "initial_filters": initial_filters, + "year_filters": year_filters, "total": context["object_list"] .aggregate(Sum("amount")) .get("amount__sum"),