This commit is contained in:
Guilhem Saurel 2017-09-10 23:27:59 +02:00
parent da2b91552f
commit 6f907aff7a
8 changed files with 69 additions and 59 deletions

View File

@ -328,6 +328,10 @@ class Talk(PonyConfModel):
def dtend(self):
return self.end_date.strftime('%Y%m%dT%H%M%SZ')
@property
def dtstamp(self):
return self.updated.strftime('%Y%m%dT%H%M%SZ')
#@property
#def materials_name(self):
# return basename(self.materials.name)

View File

@ -4,6 +4,7 @@ from django.utils.html import escape
from django.utils.timezone import localtime
from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.template.loader import get_template
from datetime import datetime, timedelta
from copy import deepcopy
@ -251,8 +252,7 @@ class Program:
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))
return get_template('cfp/planning.ics').render({'site': self.site, 'talks': self.talks})
def render(self, output='html'):
if self.cache:
@ -267,27 +267,3 @@ 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.title}
LOCATION:{talk.room}
STATUS: CONFIRMED
DESCRIPTION:{talk.description}
UID:{site.domain}/{talk.id}
END:VEVENT
"""

View File

View File

@ -0,0 +1,19 @@
BEGIN:VCALENDAR
PRODID:-//{{ site.domain }}//{{ site.name }}//FR
X-WR-CALNAME:PonyConf
X-WR-TIMEZONE:Europe/Paris
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
{% for talk in talks %}
BEGIN:VEVENT
DTSTAMP:{{ talk.dtstamp }}
DTSTART:{{ talk.dtstart }}
DTEND:{{ talk.dtend }}
SUMMARY:{{ talk.title }}
LOCATION:{{ talk.room }}
STATUS:{% if talk.accepted %}CONFIRMED{% else %}TENTATIVE{% endif %}
DESCRIPTION:{{ talk.description }}
UID:{{ site.domain }}/{{ talk.id }}
END:VEVENT{% endfor %}
END:VCALENDAR

View File

@ -1,3 +1,4 @@
from math import ceil
from django.core.mail import send_mail
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import get_object_or_404, redirect, render
@ -480,7 +481,18 @@ def schedule(request, program_format, pending, cache, template):
elif program_format == 'xml':
return HttpResponse(program.render('xml'), content_type="application/xml")
elif program_format == 'ics':
return HttpResponse(program.render('ics'), content_type="text/calendar")
response = HttpResponse('', content_type='text/plain')
response['Content-Disposition'] = 'attachment; filename="planning.ics"'
ics = []
for line in program.render('ics').split('\n'):
line = line.strip()
if len(line) < 50:
ics.append(line)
else: # https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html
for i in range(ceil(len(line) / 50)):
ics.append((' ' if i > 0 else '') + line[i * 50:(i + 1) * 50])
response.write('\r\n'.join([line for line in ics if line]))
return response
else:
raise Http404(_("Format '%s' not available" % program_format))

View File

@ -4,30 +4,26 @@
#
# pip-compile --output-file requirements-dev.txt requirements-dev.in
#
-e git+git://github.com/Nim65s/django-YummyEmailOrUsernameInsensitiveAuth.git#egg=django-yeouia
bleach==2.0.0
chardet==3.0.4
decorator==4.0.11 # via ipython
django-appconf==1.0.2 # via django-avatar, django-select2
decorator==4.1.2 # via ipython
django-appconf==1.0.2 # via django-select2
django-autoslug==1.9.3
django-avatar==4.0.0
django-bootstrap3==8.2.3
django-bootstrap3==9.0.0
django-bower==5.2.0
django-colorful==1.2
django-crispy-forms==1.6.1
django-debug-toolbar==1.8
django-extensions==1.8.1
django-registration-redux==1.6
django-select2==5.10.0
django==1.11.3
django-extensions==1.9.1
django-select2==5.11.1
django==1.11.5
html5lib==0.999999999 # via bleach
ipython==6.1.0
jedi==0.10.2 # via ipython
markdown==2.6.8
olefile==0.44 # via pillow
markdown==2.6.9
pexpect==4.2.1 # via ipython
pickleshare==0.7.4 # via ipython
pillow==4.2.1 # via django-avatar
prompt-toolkit==1.0.14 # via ipython
prompt-toolkit==1.0.15 # via ipython
pygments==2.2.0 # via ipython
pytz==2017.2 # via django
simplegeneric==0.8.1 # via ipython
@ -36,6 +32,3 @@ sqlparse==0.2.3 # via django-debug-toolbar
traitlets==4.3.2 # via ipython
wcwidth==0.1.7 # via prompt-toolkit
webencodings==0.5.1 # via html5lib
# The following packages are considered to be unsafe in a requirements file:
# setuptools # via html5lib, ipython

View File

@ -3,13 +3,10 @@ django<1.12
django-autoslug
django-bootstrap3
django-bower
django-registration-redux
django-crispy-forms
django-select2
django-avatar
django-colorful
markdown
bleach
chardet
-e git://github.com/Nim65s/django-YummyEmailOrUsernameInsensitiveAuth.git#egg=django-yeouia

View File

@ -1,12 +1,21 @@
django<1.12
django-autoslug
django-bootstrap3
django-bower
django-crispy-forms
django-select2
django-colorful
markdown
bleach
chardet
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
#
bleach==2.0.0
chardet==3.0.4
django-appconf==1.0.2 # via django-select2
django-autoslug==1.9.3
django-bootstrap3==9.0.0
django-bower==5.2.0
django-colorful==1.2
django-crispy-forms==1.6.1
django-select2==5.11.1
django==1.11.5
html5lib==0.999999999 # via bleach
markdown==2.6.9
pytz==2017.2 # via django
six==1.10.0 # via bleach, django-bower, html5lib
webencodings==0.5.1 # via html5lib