From 574f97795f81d173dd0340c077908cb960bc2feb Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 8 Nov 2016 17:01:29 +0100 Subject: [PATCH] ICS planning --- planning/utils.py | 30 ++++++++++++++++++++++++++++++ planning/views.py | 2 ++ proposals/models.py | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/planning/utils.py b/planning/utils.py index 593a634..3873324 100644 --- a/planning/utils.py +++ b/planning/utils.py @@ -273,6 +273,12 @@ class Program: 'days': '\n'.join(map(lambda x: ' ' + x, days_xml.split('\n'))), } + def _as_ics(self): + if not self.initialized: + self._lazy_init() + talks = [ICS_TALK.format(site=self.site, talk=talk) for talk in self.talks] + return ICS_MAIN.format(site=self.site, talks='\n'.join(talks)) + def render(self, output='html'): if self.cache: cache_entry = 'program.%s.%s' % ('pending' if self.pending else 'final', output) @@ -286,3 +292,27 @@ class Program: def __str__(self): return self.render() + + +# FIXME definitely the wrong place for this, but hey, other templates are already here :P + +ICS_MAIN = """BEGIN:VCALENDAR +PRODID:-//{site.domain}//{site.name}//FR +X-WR-CALNAME:PonyConf +X-WR-TIMEZONE:Europe/Paris +VERSION:2.0 +CALSCALE:GREGORIAN +METHOD:PUBLISH +{talks} +END:VCALENDAR""" + +ICS_TALK = """BEGIN:VEVENT +DTSTART:{talk.dtstart} +DTEND:{talk.dtend} +SUMMARY:{talk.abstract} +LOCATION:{talk.room} +STATUS: CONFIRMED +DESCRIPTION:{talk.description} +UID:{site.domain}/{talk.id} +END:VEVENT +""" diff --git a/planning/views.py b/planning/views.py index 07bbc3c..16501d8 100644 --- a/planning/views.py +++ b/planning/views.py @@ -55,5 +55,7 @@ def program(request, pending=False, output='html', html_template='public-program return render(request, 'planning/' + html_template, {'program': program}) elif output == 'xml': return HttpResponse(program.render('xml'), content_type="application/xml") + elif output == 'ics': + return HttpResponse(program.render('ics'), content_type="text/calendar") else: raise Http404("Format not available") diff --git a/proposals/models.py b/proposals/models.py index 307500e..d363bc7 100644 --- a/proposals/models.py +++ b/proposals/models.py @@ -212,6 +212,14 @@ class Talk(PonyConfModel): else: return None # = infinity \o/ + @property + def dtstart(self): + return self.start_date.strftime('%Y%m%dT%H%M%SZ') + + @property + def dtend(self): + return self.end_date.strftime('%Y%m%dT%H%M%SZ') + class Meta: ordering = ('event__id',)