Club-related fixes.
[wolnelektury.git] / src / club / templatetags / club.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.db.models import Sum
5 from django import template
6 from django.utils.timezone import now
7 from ..helpers import get_active_schedule
8 from ..models import Schedule
9
10
11 register = template.Library()
12
13
14 @register.filter
15 def active_schedule(user):
16     return get_active_schedule(user)
17
18
19 @register.simple_tag
20 def club_active_monthly_count():
21     return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).count()
22
23 @register.simple_tag
24 def club_active_monthly_sum():
25     return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).aggregate(s=Sum('amount'))['s']
26