From 56c5bac0c6b5fc622a0b274861a98b9dca00259e Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 22 Jan 2020 15:15:17 +0100 Subject: [PATCH 1/1] Admin club counters. --- .../admin/club/schedule/change_list.html | 18 +++++++- src/club/templatetags/club.py | 42 ++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/club/templates/admin/club/schedule/change_list.html b/src/club/templates/admin/club/schedule/change_list.html index ff08cfbde..69fd851a6 100644 --- a/src/club/templates/admin/club/schedule/change_list.html +++ b/src/club/templates/admin/club/schedule/change_list.html @@ -2,6 +2,22 @@ {% load club %} {% block content %} -

Aktywne miesięczne wpłaty: {% club_active_monthly_count %} sztuk, {% club_active_monthly_sum %} zł.

+ + + + + + + + + + + + + + + + +
Aktywne miesięczne wpłaty cykliczne:{% club_active_monthly_count %} sztuk{% club_active_monthly_sum %} zł.
Aktywne roczne wpłaty cykliczne:{% club_active_yearly_count %} sztuk{% club_active_yearly_sum %} zł.
Jednorazowe wpłaty w ciągu ostatnich 30 dni:{% club_active_30day_count %} sztuk{% club_active_30day_sum %} zł.
{{ block.super }} {% endblock content %} diff --git a/src/club/templatetags/club.py b/src/club/templatetags/club.py index 7e8bc038c..b0ce86817 100644 --- a/src/club/templatetags/club.py +++ b/src/club/templatetags/club.py @@ -1,6 +1,7 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from datetime import timedelta from django.db.models import Sum from django import template from django.utils.timezone import now @@ -18,9 +19,46 @@ def active_schedule(user): @register.simple_tag def club_active_monthly_count(): - return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).count() + return Schedule.objects.filter( + expires_at__gt=now(), + monthly=True, + is_cancelled=False + ).count() @register.simple_tag def club_active_monthly_sum(): - return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).aggregate(s=Sum('amount'))['s'] + return Schedule.objects.filter( + expires_at__gt=now(), + monthly=True, + is_cancelled=False + ).aggregate(s=Sum('amount'))['s'] or 0 +@register.simple_tag +def club_active_yearly_count(): + return Schedule.objects.filter( + expires_at__gt=now(), + yearly=True, + is_cancelled=False + ).count() + +@register.simple_tag +def club_active_yearly_sum(): + return Schedule.objects.filter( + expires_at__gt=now(), + yearly=True, + is_cancelled=False + ).aggregate(s=Sum('amount'))['s'] or 0 + +@register.simple_tag +def club_active_30day_count(): + return Schedule.objects.filter( + yearly=False, monthly=False, + payed_at__gte=now() - timedelta(days=30) + ).count() + +@register.simple_tag +def club_active_30day_sum(): + return Schedule.objects.filter( + yearly=False, monthly=False, + payed_at__gte=now() - timedelta(days=30) + ).aggregate(s=Sum('amount'))['s'] or 0 -- 2.20.1