feeds.py 1.91 KB
Newer Older
1
2
from datetime import datetime, timedelta

Luuk Scholten's avatar
Luuk Scholten committed
3
4
5
6
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
32
33
34
35
36
37
38
39
40
41
42
43
44
from django.urls import reverse
from django.utils.translation import activate
from django_ical.views import ICalFeed
from events.models import Event
from django.utils.translation import ugettext as _


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):
        return item.description

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

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

    def item_link(self, item):
        return reverse('events:event', kwargs={'event_id': item.id})

    def item_location(self, item):
        return "{} - {}".format(item.location, item.map_location)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65


class DeprecationFeed(ICalFeed):
    def product_id(self):
        return '-//thalia.nu//DEPRECATED'

    def items(self):
        return range(7)

    def item_start_datetime(self, item):
        today = datetime.now().replace(hour=13, minute=37, second=0)
        delta = timedelta(days=item)
        return today + delta

    def item_end_datetime(self, item):
        today = datetime.now().replace(hour=15, minute=37, second=0)
        delta = timedelta(days=item)
        return today + delta

    def item_title(self, item):
        return (
Sébastiaan Versteeg's avatar
Fix //    
Sébastiaan Versteeg committed
66
            'Oude Thalia Feed, gebruik https://thalia.nu' +
67
68
69
70
71
            reverse('events:ical-nl')
        )

    def item_link(self, item):
        return reverse('events:ical-nl') + '?item={}'.format(item)