event_cards.py 793 Bytes
Newer Older
1
2
3
from django import template
from django.utils import timezone

4
from events import services
5
6
7
8
9
from events.models import Event

register = template.Library()


10
11
@register.inclusion_tag('events/cards.html', takes_context=True)
def show_cards(context):
12
13
14
15
    upcoming_events = Event.objects.filter(
        published=True,
        end__gte=timezone.now()
    ).order_by('end')
16
17
18
19

    try:
        upcoming = [{
                'event': x,
20
                'current_user_registration': services.is_user_registered(
21
                    context['user'], x),
22
23
24
25
26
27
28
29
            } for x in upcoming_events[:4]]
    except AttributeError:
        upcoming = [{
                'event': x,
                'current_user_registration': None
            } for x in upcoming_events[:4]]

    return {'upcoming': upcoming}