event_cards.py 763 Bytes
Newer Older
1
2
3
4
5
6
7
8
from django import template
from django.utils import timezone

from events.models import Event

register = template.Library()


9
10
@register.inclusion_tag('events/cards.html', takes_context=True)
def show_cards(context):
11
12
13
14
    upcoming_events = Event.objects.filter(
        published=True,
        end__gte=timezone.now()
    ).order_by('end')
15
16
17
18
19
20
21
22
23
24
25
26
27
28

    try:
        upcoming = [{
                'event': x,
                'current_user_registration': x.is_member_registered(
                    context['user'].member)
            } for x in upcoming_events[:4]]
    except AttributeError:
        upcoming = [{
                'event': x,
                'current_user_registration': None
            } for x in upcoming_events[:4]]

    return {'upcoming': upcoming}