feeds.py 1.31 KB
Newer Older
1
from django.contrib.sites.models import Site
Luuk Scholten's avatar
Luuk Scholten committed
2
from django.urls import reverse
3
from django.utils.translation import ugettext as _
Luuk Scholten's avatar
Luuk Scholten committed
4
5
from django.utils.translation import activate
from django_ical.views import ICalFeed
6

Luuk Scholten's avatar
Luuk Scholten committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from events.models import Event


class EventFeed(ICalFeed):
    def __init__(self, lang='en'):
        super().__init__()
        self.lang = lang

    def product_id(self):
        return '-//thalia.nu//EventCalendar//' + self.lang.upper()

    def file_name(self):
        return "thalia_{}.ics".format(self.lang)

    def title(self):
        activate(self.lang)
        return _('Study Association Thalia event calendar')

    def items(self):
        return Event.objects.filter(published=True).order_by('-start')

    def item_title(self, item):
        return item.title

    def item_description(self, item):
32
33
34
35
        return (item.description +
                ' <a href="https://%s%s">Website</a>' %
                (Site.objects.get_current().domain,
                 self.item_link(item)))
Luuk Scholten's avatar
Luuk Scholten committed
36
37
38
39
40
41
42
43

    def item_start_datetime(self, item):
        return item.start

    def item_end_datetime(self, item):
        return item.end

    def item_link(self, item):
44
        return reverse('events:event', kwargs={'pk': item.id})
Luuk Scholten's avatar
Luuk Scholten committed
45
46
47

    def item_location(self, item):
        return "{} - {}".format(item.location, item.map_location)