Admin club counters.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 22 Jan 2020 14:15:17 +0000 (15:15 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 22 Jan 2020 14:15:17 +0000 (15:15 +0100)
src/club/templates/admin/club/schedule/change_list.html
src/club/templatetags/club.py

index ff08cfb..69fd851 100644 (file)
@@ -2,6 +2,22 @@
 {% load club %}
 
 {% block content %}
-  <p>Aktywne miesięczne wpłaty: {% club_active_monthly_count %} sztuk, {% club_active_monthly_sum %} zł.</p>
+  <table class="table">
+    <tr>
+      <td>Aktywne miesięczne wpłaty cykliczne:</td>
+      <td>{% club_active_monthly_count %} sztuk</td>
+      <td>{% club_active_monthly_sum %} zł.</td>
+    </tr>
+    <tr>
+      <td>Aktywne roczne wpłaty cykliczne:</td>
+      <td>{% club_active_yearly_count %} sztuk</td>
+      <td>{% club_active_yearly_sum %} zł.</td>
+    </tr>
+    <tr>
+      <td>Jednorazowe wpłaty w ciągu ostatnich 30 dni:</td>
+      <td>{% club_active_30day_count %} sztuk</td>
+      <td>{% club_active_30day_sum %} zł.</td>
+    </tr>
+  </table>
   {{ block.super }}
 {% endblock content %}
index 7e8bc03..b0ce868 100644 (file)
@@ -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