Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra dropdowns for every year in payment history #3840

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):

for i in range(85):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

85 is kind of a weird number?... Is it based on the legal storage period for payment info? For the user it might be nice if years in which there were no payments (or at least years before their first payment) are not shown.

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"),
Expand Down