diff --git a/cfp/planning.py b/cfp/planning.py
index e17699d..5490eec 100644
--- a/cfp/planning.py
+++ b/cfp/planning.py
@@ -10,6 +10,7 @@ from copy import deepcopy
from collections import OrderedDict, namedtuple
from itertools import islice
from zlib import adler32
+import xml.etree.ElementTree as ET
from .models import Conference, Talk, Room
@@ -172,113 +173,80 @@ class Program:
def _as_xml(self):
if not self.initialized:
self._lazy_init()
- result = """
-
-%(conference)s
-%(days)s
-
-"""
+ schedule = ET.Element('schedule')
- if not len(self.days):
- return result % {'conference': '', 'days': ''}
+ #if not len(self.days):
+ # return result % {'conference': '', 'days': ''}
- conference_xml = """
- %(title)s
-
- %(venue)s
- %(city)s
- %(start_date)s
- %(end_date)s
- %(days_count)s
- 09:00:00
- 00:05:00
-
-""" % {
- 'title': self.site.name,
- 'venue': ', '.join(map(lambda x: x.strip(), self.conference.venue.split('\n'))),
- 'city': self.conference.city,
- 'start_date': sorted(self.days.keys())[0].strftime('%Y-%m-%d'),
- 'end_date': sorted(self.days.keys(), reverse=True)[0].strftime('%Y-%m-%d'),
- 'days_count': len(self.days),
- }
+ conference = ET.SubElement(schedule, 'conference')
+ elt = ET.SubElement(conference, 'title')
+ elt.text = self.site.name
+ elt = ET.SubElement(conference, 'venue')
+ elt.text = ', '.join(map(lambda x: x.strip(), self.conference.venue.split('\n')))
+ elt = ET.SubElement(conference, 'city')
+ elt.text = self.conference.city
+ elt = ET.SubElement(conference, 'start_date')
+ elt.text = sorted(self.days.keys())[0].strftime('%Y-%m-%d')
+ elt = ET.SubElement(conference, 'end_date')
+ elt.text = sorted(self.days.keys(), reverse=True)[0].strftime('%Y-%m-%d')
+ elt = ET.SubElement(conference, 'days_count')
+ elt.text = str(len(self.days))
- days_xml = ''
for index, day in enumerate(sorted(self.days.keys())):
- days_xml += '\n' % {
- 'index': index + 1,
- 'date': day.strftime('%Y-%m-%d'),
- }
+ day_elt = ET.SubElement(schedule, 'day', index=str(index+1), date=day.strftime('%Y-%m-%d'))
for room in self.rooms.all():
- days_xml += ' \n' % room.name
+ room_elt = ET.SubElement(day_elt, 'room', name=room.name)
for talk in self.talks.filter(room=room).order_by('start_date'):
if localtime(talk.start_date).date() != day:
continue
+ talk_elt = ET.SubElement(day_elt, 'event', id=str(talk.id))
duration = talk.estimated_duration
- persons = ''
+ persons_elt = ET.SubElement(talk_elt, 'persons')
for speaker in talk.speakers.all():
- persons += ' %(person)s\n' % {
- 'person_id': speaker.id,
- 'person': str(speaker),
- }
- links = ''
- registration = ''
- #if talk.registration_required and self.conference.subscriptions_open:
- # links += mark_safe("""
- # %(link)s""" % {
- # 'link': reverse('register-for-a-talk', args=[talk.slug]),
- # })
- # registration = """
- # %(max)s
- # %(remain)s""" % {
- # 'max': talk.attendees_limit,
- # 'remain': talk.remaining_attendees or 0,
- # }
- #if talk.materials:
- # links += mark_safe("""
- # %(link)s""" % {
- # 'link': talk.materials.url,
- # })
- #if talk.video:
- # links += mark_safe("""
- # %(link)s""" % {
- # 'link': talk.video,
- # })
- days_xml += """
- %(start)s
- %(duration)s
- %(room)s
- %(slug)s
- %(title)s
-
-
- %(type)s
-
- %(description)s
-
-%(persons)s
- %(links)s
- %(registration)s
- \n""" % {
- 'id': talk.id,
- 'start': localtime(talk.start_date).strftime('%H:%M'),
- 'duration': '%02d:%02d' % (talk.estimated_duration / 60, talk.estimated_duration % 60),
- 'room': escape(room.name),
- 'slug': escape(talk.slug),
- 'title': escape(talk.title),
- 'track': escape(talk.track or ''),
- 'type': escape(talk.category.label),
- 'description': escape(talk.description),
- 'persons': persons,
- 'links': links,
- 'registration': registration,
- }
- days_xml += ' \n'
- days_xml += '\n'
+ person_elt = ET.SubElement(talk_elt, 'person', id=str(speaker.id))
+ person_elt.text = str(speaker)
+# #if talk.registration_required and self.conference.subscriptions_open:
+# # links += mark_safe("""
+# # %(link)s""" % {
+# # 'link': reverse('register-for-a-talk', args=[talk.slug]),
+# # })
+# # registration = """
+# # %(max)s
+# # %(remain)s""" % {
+# # 'max': talk.attendees_limit,
+# # 'remain': talk.remaining_attendees or 0,
+# # }
+# #if talk.materials:
+# # links += mark_safe("""
+# # %(link)s""" % {
+# # 'link': talk.materials.url,
+# # })
+# #if talk.video:
+# # links += mark_safe("""
+# # %(link)s""" % {
+# # 'link': talk.video,
+# # })
+ elt = ET.SubElement(talk_elt, 'start')
+ elt.text = localtime(talk.start_date).strftime('%H:%M')
+ elt = ET.SubElement(talk_elt, 'duration')
+ elt.text = '%02d:%02d' % (talk.estimated_duration / 60, talk.estimated_duration % 60)
+ elt = ET.SubElement(talk_elt, 'room')
+ elt.text = room.name
+ elt = ET.SubElement(talk_elt, 'slug')
+ elt.text = talk.slug
+ elt = ET.SubElement(talk_elt, 'title')
+ elt.text = talk.title
+ elt = ET.SubElement(talk_elt, 'subtitle')
+ elt = ET.SubElement(talk_elt, 'track')
+ elt.text = talk.track or ''
+ elt = ET.SubElement(talk_elt, 'type')
+ elt.text = talk.category.label
+ elt = ET.SubElement(talk_elt, 'language')
+ elt = ET.SubElement(talk_elt, 'description')
+ elt.text = talk.description
+ elt = ET.SubElement(talk_elt, 'links')
- return result % {
- 'conference': '\n'.join(map(lambda x: ' ' + x, conference_xml.split('\n'))),
- 'days': '\n'.join(map(lambda x: ' ' + x, days_xml.split('\n'))),
- }
+ return ET.tostring(schedule)
def _as_ics(self):
if not self.initialized: