ICS planning

This commit is contained in:
Guilhem Saurel 2016-11-08 17:01:29 +01:00
parent 5c2ecb932b
commit 574f97795f
3 changed files with 40 additions and 0 deletions

View File

@ -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
"""

View File

@ -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")

View File

@ -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',)