diff --git a/backend/donations/views/my_account.py b/backend/donations/views/my_account.py index f06cad1e..e43e782a 100644 --- a/backend/donations/views/my_account.py +++ b/backend/donations/views/my_account.py @@ -1,8 +1,13 @@ +from collections import OrderedDict + +from django.conf import settings from django.contrib.auth.decorators import login_required +from django.db.models import Q, QuerySet from django.shortcuts import render +from django.utils import timezone from django.utils.decorators import method_decorator -from ..models import Ngo +from ..models import Donor, Ngo from .base import AccountHandler @@ -31,9 +36,22 @@ class MyAccountHandler(AccountHandler): template_name = "ngo/my-account.html" def get(self, request, *args, **kwargs): + user_ngo: Ngo = request.user.ngo if request.user.ngo else None + donors: QuerySet[Donor] = Donor.objects.filter(Q(ngo=user_ngo)).order_by("-date_created") + + years = range(timezone.now().year, settings.START_YEAR, -1) + + grouped_donors = OrderedDict() + for donor in donors: + index = donor.date_created.year + if index in years: + grouped_donors[index].append(donor) + context = { "user": request.user, - "ngo": request.user.ngo if request.user.ngo else None, + "limit": settings.DONATIONS_LIMIT, + "ngo": user_ngo, + "donors": grouped_donors, } return render(request, self.template_name, context) diff --git a/backend/templates/v1/components/ngo-header.html b/backend/templates/v1/components/ngo-header.html index c8723e7f..1f7d7cc3 100644 --- a/backend/templates/v1/components/ngo-header.html +++ b/backend/templates/v1/components/ngo-header.html @@ -12,7 +12,7 @@
Mai jos găsești o listă cu toate persoanele care au completat formularul de redirectionare:
- {% for key, value in donors.iteritems() %} + {% for key, value in donors.items() %} {% if value or key == current_year %}{{ key }}
diff --git a/backend/templates/v1/ngo/my-account.html b/backend/templates/v1/ngo/my-account.html index 0722d69b..f77bd2fd 100644 --- a/backend/templates/v1/ngo/my-account.html +++ b/backend/templates/v1/ngo/my-account.html @@ -38,7 +38,7 @@