Skip to content

Commit

Permalink
Safe ical rendering if no speakers
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaith committed Jul 9, 2015
1 parent f0da350 commit b3e1ce2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions talks/core/renderers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import datetime, timedelta
from icalendar.cal import Alarm

from rest_framework import renderers
from icalendar import Calendar, Event
Expand Down Expand Up @@ -26,8 +27,10 @@ def _event_to_ics(e):
event.add('summary', e['title_display'])
if 'description' in e:
desc_with_speakers = e['description']
speakers_list = "Speakers:\n" + ", ".join(get_speaker_name(speaker) for speaker in e['speakers'])
event.add('description', desc_with_speakers + "\n" + speakers_list)
speakers_list = ""
if 'speakers' in e:
speakers_list = "\nSpeakers:\n" + ", ".join(get_speaker_name(speaker) for speaker in e['speakers'])
event.add('description', desc_with_speakers + speakers_list)
if 'start' in e:
event.add('dtstart', dt_string_to_object(e['start']))
if 'end' in e:
Expand All @@ -37,8 +40,16 @@ def _event_to_ics(e):
event.add('uid', e['full_url'])
if 'location' in e:
event.add('location', e['location'])

alarm = Alarm()
alarm.add('action', 'display')
alarm.add('trigger', timedelta(hours=-1))
alarm.add('description', "Talk:" + e['title_display'])
event.add_component(alarm)

return event


def get_speaker_name(speaker):
name = speaker['name']
if(speaker['bio']):
Expand Down

0 comments on commit b3e1ce2

Please sign in to comment.