1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from datetime import timedelta
5 from django.db.models import Sum
6 from django import template
7 from django.utils.timezone import now
8 from ..helpers import get_active_schedule
9 from ..models import Schedule
12 register = template.Library()
16 def active_schedule(user):
17 return get_active_schedule(user)
21 def club_active_monthly_count():
22 return Schedule.objects.filter(
29 def club_active_monthly_sum():
30 return Schedule.objects.filter(
34 ).aggregate(s=Sum('amount'))['s'] or 0
37 def club_active_yearly_count():
38 return Schedule.objects.filter(
45 def club_active_yearly_sum():
46 return Schedule.objects.filter(
50 ).aggregate(s=Sum('amount'))['s'] or 0
53 def club_active_30day_count():
54 return Schedule.objects.filter(
55 yearly=False, monthly=False,
56 payed_at__gte=now() - timedelta(days=30)
60 def club_active_30day_sum():
61 return Schedule.objects.filter(
62 yearly=False, monthly=False,
63 payed_at__gte=now() - timedelta(days=30)
64 ).aggregate(s=Sum('amount'))['s'] or 0