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_count_recurring():
22 return Schedule.objects.exclude(monthly=False, yearly=False).filter(expires_at__gt=now()).count()
25 def club_active_monthly_count():
26 return Schedule.objects.filter(
33 def club_active_monthly_sum():
34 return Schedule.objects.filter(
38 ).aggregate(s=Sum('amount'))['s'] or 0
41 def club_active_yearly_count():
42 return Schedule.objects.filter(
49 def club_active_yearly_sum():
50 return Schedule.objects.filter(
54 ).aggregate(s=Sum('amount'))['s'] or 0
57 def club_active_30day_count():
58 return Schedule.objects.filter(
59 yearly=False, monthly=False,
60 payed_at__gte=now() - timedelta(days=30)
64 def club_active_30day_sum():
65 return Schedule.objects.filter(
66 yearly=False, monthly=False,
67 payed_at__gte=now() - timedelta(days=30)
68 ).aggregate(s=Sum('amount'))['s'] or 0
72 def club_monthly_since(start):
73 return Schedule.objects.filter(
74 monthly=True, payed_at__gte=start).count()
78 def club_monthly_missing_since(start, target):
79 return target - Schedule.objects.filter(
80 monthly=True, payed_at__gte=start).count()
84 def invite_payment(payment_method, schedule):
85 return payment_method.invite_widget(schedule)