Commit f76ddc0a authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Added token-based personal iCal feed

parent f5d3aa7a
"""The feeds defined by the events package"""
from django.db.models.query_utils import Q
from django.contrib.sites.models import Site
from django.urls import reverse
from django.utils.translation import ugettext as _
from django.utils.translation import activate
from django_ical.views import ICalFeed
from events.models import Event
from events.models import Event, FeedToken
class EventFeed(ICalFeed):
......@@ -13,6 +14,15 @@ class EventFeed(ICalFeed):
def __init__(self, lang='en'):
super().__init__()
self.lang = lang
self.user = None
def __call__(self, request, *args, **kwargs):
if 'u' in request.GET:
self.user = FeedToken.get_member(request.GET['u'])
else:
self.user = None
return super().__call__(request, args, kwargs)
def product_id(self):
return '-//thalia.nu//EventCalendar//' + self.lang.upper()
......@@ -25,7 +35,13 @@ class EventFeed(ICalFeed):
return _('Study Association Thalia event calendar')
def items(self):
return Event.objects.filter(published=True).order_by('-start')
query = Q(published=True)
if self.user:
query &= (Q(registration_start__isnull=True) |
Q(registration__member=self.user))
return Event.objects.filter(query).order_by('-start')
def item_title(self, item):
return item.title
......
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-23 19:03+0200\n"
"PO-Revision-Date: 2018-05-23 19:05+0200\n"
"POT-Creation-Date: 2018-06-13 20:59+0200\n"
"PO-Revision-Date: 2018-06-13 21:00+0200\n"
"Last-Translator: Sébastiaan Versteeg <se_bastiaan@outlook.com>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -16,7 +16,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.4\n"
"X-Generator: Poedit 2.0.6\n"
#: admin.py:96
msgid "Event Date"
......@@ -119,7 +119,7 @@ msgstr "Evenementen"
msgid "[THALIA] Notification about your registration for '{}'"
msgstr "[THALIA] Bericht over je aanmelding voor ‘{}’"
#: feeds.py:23
#: feeds.py:33
msgid "Study Association Thalia event calendar"
msgstr "Studievereniginig Thalia evenementenkalender"
......@@ -127,63 +127,63 @@ msgstr "Studievereniginig Thalia evenementenkalender"
msgid "order"
msgstr "volgorde"
#: models.py:19
#: models.py:21
msgid "Drinks"
msgstr "Borrel"
#: models.py:20
#: models.py:22
msgid "Activity"
msgstr "Activiteit"
#: models.py:21
#: models.py:23
msgid "Lunch Lecture"
msgstr "Lunchlezing"
#: models.py:22
#: models.py:24
msgid "General Meeting"
msgstr "Algemene ledenvergadering"
#: models.py:23
#: models.py:25
msgid "Workshop"
msgstr "Workshop"
#: models.py:24
#: models.py:26
msgid "Other"
msgstr "Overig"
#: models.py:26 templates/events/event.html:168
#: models.py:28 templates/events/event.html:168
msgid "No registration required"
msgstr "Geen aanmelding vereist"
#: models.py:30 templates/events/admin/details.html:71
#: models.py:32 templates/events/admin/details.html:71
msgid "title"
msgstr "titel"
#: models.py:36 models.py:432
#: models.py:38 models.py:434
msgid "description"
msgstr "beschrijving"
#: models.py:39
#: models.py:41
msgid "start time"
msgstr "starttijd"
#: models.py:41
#: models.py:43
msgid "end time"
msgstr "eindtijd"
#: models.py:46 templates/events/admin/details.html:75
#: models.py:48 templates/events/admin/details.html:75
msgid "organiser"
msgstr "organisator"
#: models.py:52
#: models.py:54
msgid "category"
msgstr "categorie"
#: models.py:57
#: models.py:59
msgid "registration start"
msgstr "start aanmelden"
#: models.py:60 models.py:69
#: models.py:62 models.py:71
msgid ""
"If you set a registration period registration will be required. If you don't "
"set one, registration won't be required."
......@@ -191,19 +191,19 @@ msgstr ""
"Als je een aanmeldperiode instelt is aanmelden vereist, als je dat niet doet "
"is aanmelden niet vereist."
#: models.py:66
#: models.py:68
msgid "registration end"
msgstr "einde aanmelden"
#: models.py:75 templates/events/admin/details.html:82
#: models.py:77 templates/events/admin/details.html:82
msgid "cancel deadline"
msgstr "afmelddeadline"
#: models.py:81
#: models.py:83
msgid "send cancellation notifications"
msgstr "verstuur afmeldnotificaties"
#: models.py:83
#: models.py:85
msgid ""
"Send an email to the organising party when a member cancels their "
"registration after the deadline."
......@@ -211,16 +211,16 @@ msgstr ""
"Verzend een e-mail naar de organiserende partij wanneer een lid zich na de "
"afmelddeadline afmeld voor een evenement."
#: models.py:89 templates/events/admin/details.html:85
#: models.py:91 templates/events/admin/details.html:85
#: templates/events/event.html:38
msgid "location"
msgstr "locatie"
#: models.py:94
#: models.py:96
msgid "location for minimap"
msgstr "locatie voor minimap"
#: models.py:96
#: models.py:98
msgid ""
"Location of Huygens: Heyendaalseweg 135, Nijmegen. Location of Mercator 1: "
"Toernooiveld 212, Nijmegen. Not shown as text!!"
......@@ -228,150 +228,150 @@ msgstr ""
"Locatie van ’t Huygens: Heyendaalseweg 135, Nijmegen. Locatie van Mercator "
"1: Toernooiveld 212, Nijmegen. Dit veld wordt niet getoond als tekst!!"
#: models.py:102 templates/events/admin/details.html:87
#: models.py:104 templates/events/admin/details.html:87
#: templates/events/event.html:43
msgid "price"
msgstr "prijs"
#: models.py:110
#: models.py:112
msgid "fine"
msgstr "boete"
#: models.py:116
#: models.py:118
msgid "Fine if participant does not show up (at least €5)."
msgstr "Boete als deelnemer niet komt opdagen (minimaal €5)."
#: models.py:121
#: models.py:123
msgid "maximum number of participants"
msgstr "maximum aantal deelnemers"
#: models.py:128
#: models.py:130
msgid "message when there is no registration"
msgstr "bericht dat getoond wordt wanneer aanmelden niet nodig is"
#: models.py:132
#: models.py:134
msgid "Default:"
msgstr "Standaard:"
#: models.py:136
#: models.py:138
msgid "published"
msgstr "gepubliceerd"
#: models.py:209
#: models.py:211
msgid "Start cannot have an empty date or time field"
msgstr "Starttijd kan niet een lege datum of tijd hebben"
#: models.py:213
#: models.py:215
msgid "End cannot have an empty date or time field"
msgstr "Eindtijd kan niet een lege datum of tijd hebben"
#: models.py:218
#: models.py:220
msgid "Can't have an event travel back in time"
msgstr "Een evenement kan niet terugreizen in de tijd"
#: models.py:222
#: models.py:224
msgid "The fine for this event is too low (must be at least €5)."
msgstr "De boete voor dit evenement is te laag (minimaal €5)."
#: models.py:229
#: models.py:231
msgid "Doesn't make sense to have this if you require registrations."
msgstr "Het is niet logisch om dit te hebben als je aanmelden vereist."
#: models.py:234
#: models.py:236
msgid "If registration is required, you need a start of registration"
msgstr ""
"Als aanmelden vereist is, dan heb je een starttijd voor de aanmeldperiode "
"nodig"
#: models.py:239
#: models.py:241
msgid "If registration is required, you need an end of registration"
msgstr ""
"Als aanmelden vereist is, dan heb je een eindtijd voor de aanmeldperiode "
"nodig"
#: models.py:244
#: models.py:246
msgid "If registration is required, you need a deadline for the cancellation"
msgstr ""
"Als aanmelden vereist is, dan heb je een eindtijd voor de aanmeldperiode "
"nodig"
#: models.py:249
#: models.py:251
msgid "The cancel deadline should be before the start of the event."
msgstr "De afmelddeadline moet voor de start van het evenement liggen."
#: models.py:253
#: models.py:255
msgid "Registration start should be before registration end"
msgstr "De starttijd voor de aanmeldperiode moet voor de eindtijd liggen"
#: models.py:262
#: models.py:264
msgid "This organiser does not have a contact mailinglist."
msgstr "De organisator heeft geen contact mailinglijst."
#: models.py:296
#: models.py:298
msgid "No payment"
msgstr "Niet betaald"
#: models.py:297
#: models.py:299
msgid "Paid with cash"
msgstr "Contant betaald"
#: models.py:298
#: models.py:300
msgid "Paid with card"
msgstr "Pin betaald"
#: models.py:310 templates/events/admin/registrations_table.html:6
#: models.py:312 templates/events/admin/registrations_table.html:6
msgid "name"
msgstr "naam"
#: models.py:312
#: models.py:314
msgid "Use this for non-members"
msgstr "Gebruikt dit voor niet-leden"
#: models.py:317 templates/events/admin/registrations_table.html:7
#: models.py:319 templates/events/admin/registrations_table.html:7
msgid "registration date"
msgstr "aanmelddatum"
#: models.py:319 templates/events/admin/registrations_table.html:9
#: models.py:321 templates/events/admin/registrations_table.html:9
msgid "cancellation date"
msgstr "afmelddatum"
#: models.py:324 templates/events/admin/registrations_table.html:14
#: models.py:326 templates/events/admin/registrations_table.html:14
msgid "present"
msgstr "aanwezig"
#: models.py:331
#: models.py:333
msgid "payment"
msgstr "betaling"
#: models.py:388 models.py:389
#: models.py:390 models.py:391
msgid "Either specify a member or a name"
msgstr "Geef een lid of een naam op"
#: models.py:412
#: models.py:414
msgid "Checkbox"
msgstr "Checkbox"
#: models.py:413
#: models.py:415
msgid "Text"
msgstr "Text"
#: models.py:414
#: models.py:416
msgid "Integer"
msgstr "Integer"
#: models.py:419
#: models.py:421
msgid "field type"
msgstr "veldtype"
#: models.py:426
#: models.py:428
msgid "field name"
msgstr "veldnaam"
#: models.py:438
#: models.py:440
msgid "required"
msgstr "verplicht"
#: models.py:490
#: models.py:492
msgid "last changed"
msgstr "laatst aangepast"
......@@ -702,16 +702,24 @@ msgstr "Aanmeldingen"
msgid "cohort"
msgstr "cohort"
#: templates/events/index.html:85 templates/events/index.html:87
#: templates/events/index.html:93
#: templates/events/index.html:25
msgid "iCal feed (all events)"
msgstr "iCal feed (alle evenementen)"
#: templates/events/index.html:36
msgid "iCal feed (personal)"
msgstr "iCal feed (persoonlijk)"
#: templates/events/index.html:97 templates/events/index.html:99
#: templates/events/index.html:105
msgid "hide birthdays"
msgstr "verberg verjaardagen"
#: templates/events/index.html:85 templates/events/index.html:88
#: templates/events/index.html:97 templates/events/index.html:100
msgid "show birthdays"
msgstr "toon verjaardagen"
#: templates/events/index.html:106
#: templates/events/index.html:118
msgid "list"
msgstr "lijst"
......
# Generated by Django 2.0.6 on 2018-06-13 19:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('members', '0021_emailchange'),
('events', '0025_auto_20180112_1214'),
]
operations = [
migrations.CreateModel(
name='FeedToken',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('token', models.CharField(editable=False, max_length=32)),
('member', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='members.Member')),
],
),
]
......@@ -6,6 +6,7 @@ from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils import timezone
from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
from django.utils.text import format_lazy
from tinymce.models import HTMLField
......@@ -512,3 +513,24 @@ class TextRegistrationInformation(AbstractRegistrationInformation):
class IntegerRegistrationInformation(AbstractRegistrationInformation):
"""Checkbox information filled in by members when registering"""
value = models.IntegerField()
class FeedToken(models.Model):
"""Used to personalize the ical Feed"""
member = models.OneToOneField('members.Member', models.CASCADE)
token = models.CharField(max_length=32, editable=False)
def save(self, *args, **kwargs):
self.token = get_random_string(32)
super().save(*args, **kwargs)
@staticmethod
def get_member(token):
try:
return FeedToken.objects.get(token=token).member
except FeedToken.DoesNotExist:
return None
def __str__(self):
return '{} ({})'.format(self.member.get_full_name(), self.token)
{% extends "base.html" %}
{% load i18n static compress %}}
{% load i18n static compress personal_feed %}}
{% get_current_language as LANGUAGE_CODE %}
{% block title %}{% trans "Calendar"|capfirst %} — {{ block.super }}{% endblock %}
......@@ -19,14 +19,24 @@
<span class="title-meta clearfix">
<span>
<a href="{% url 'events:ical-'|add:LANGUAGE_CODE %}"
id="collectionButton"
target="_blank"
class="calendar"
title="iCal feed"
title="{% trans 'iCal feed (all events)' %}"
>
<i class="fa fa-calendar"></i>
</a>
</span>
{% if request.user.is_authenticated %}
<span>
<a href="{% url 'events:ical-'|add:LANGUAGE_CODE %}?u={% personal_feed %}"
target="_blank"
class="calendar"
title="{% trans 'iCal feed (personal)' %}"
>
<i class="fa fa-calendar"></i>
</a>
</span>
{% endif %}
</span>
</h1>
......
from django.template import Library
from events.models import FeedToken
register = Library()
@register.simple_tag(takes_context=True)
def personal_feed(context):
"""
Returns a personal token for the ical feed
"""
member = context['request'].user
return FeedToken.objects.get_or_create(member=member)[0].token
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment