Skip to content

Commit

Permalink
Add extra dropdowns for every year in payment history
Browse files Browse the repository at this point in the history
  • Loading branch information
bpc committed Nov 13, 2024
1 parent 2c3a429 commit 725e5fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 6 additions & 3 deletions website/payments/templates/payments/payment_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,31 @@ <h5 class="mb-4">
</h5>
{% endif %}
<ul class="nav nav-tabs mb-4">
{% for filter in filters|slice:':6' %}
{% for filter in initial_filters %}
<li class="nav-item">
<a class="nav-link {% if filter.year == year and filter.month == month %}active{% endif %}"
href="{% url 'payments:payment-list' filter.year filter.month %}">
{{ filter.year }}-{{ filter.month|stringformat:"02d" }}
</a>
</li>
{% endfor %}
{% for filter_group in year_filters %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle {% if filters.6.year == year and filters.6.month >= month or filters.6.year > year and filters.6.month < month %}active{% endif %}"
data-bs-toggle="dropdown"
data-bs-display="static"
href="#" role="button" aria-haspopup="true"
aria-expanded="false">{% trans 'Older' %}</a>
aria-expanded="false">{{ filter_group.year }}</a>
<div class="dropdown-menu">
{% for filter in filters|slice:'6:' %}
{% for filter in filter_group.months %}
<a class="dropdown-item {% if filter.year == year and filter.month == month %}active{% endif %}"
href="{% url 'payments:payment-list' filter.year filter.month %}">
{{ filter.year }}-{{ filter.month|stringformat:"02d" }}
</a>
{% endfor %}
</div>
</li>
{% endfor %}
</ul>
{% if object_list %}
<table class="table">
Expand Down
12 changes: 10 additions & 2 deletions website/payments/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from decimal import Decimal
from itertools import groupby

from django.apps import apps
from django.conf import settings
Expand Down Expand Up @@ -145,14 +146,21 @@ def get_queryset(self) -> QuerySet:

def get_context_data(self, *args, **kwargs):
filters = []
for i in range(13):

Check failure on line 149 in website/payments/views.py

View workflow job for this annotation

GitHub Actions / Linting

Ruff (W293)

website/payments/views.py:149:1: W293 Blank line contains whitespace
for i in range(85):
new_now = timezone.now() - relativedelta(months=i)
filters.append({"year": new_now.year, "month": new_now.month})

Check failure on line 153 in website/payments/views.py

View workflow job for this annotation

GitHub Actions / Linting

Ruff (W293)

website/payments/views.py:153:1: W293 Blank line contains whitespace
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"),
Expand Down

0 comments on commit 725e5fa

Please sign in to comment.