adapt ics code to work with eventinstances instead of the old event.days system

This commit is contained in:
Thomas Steen Rasmussen 2017-03-31 19:42:10 +02:00
parent 33689c5270
commit 35f22bdb71
2 changed files with 9 additions and 21 deletions

View file

@ -1,25 +1,13 @@
import icalendar import icalendar
from icalendar import vDatetime
def gen_ics(eventinstances):
def gen_icalevents(event):
for i in event.days.all():
ievent = icalendar.Event()
ievent['summary'] = event.title
newdate = datetime.datetime.combine(i.date, datetime.time(event.start.hour, event.start.minute, event.start.second))
ievent['dtstart'] = vDatetime(newdate).to_ical()
newdate = datetime.datetime.combine(i.date, datetime.time(event.end.hour, event.end.minute, event.end.second))
ievent['dtend'] = vDatetime(newdate).to_ical()
yield ievent
def gen_ics(events):
cal = icalendar.Calendar() cal = icalendar.Calendar()
for event in events: for eventinstance in eventinstances:
for ical_event in gen_icalevents(event): ievent = icalendar.Event()
cal.add_component(ical_event) ievent['summary'] = eventinstance.event.title
ievent['dtstart'] = icalendar.vDatetime(eventinstance.when.lower).to_ical()
ievent['dtend'] = icalendar.vDatetime(eventinstance.when.upper).to_ical()
cal.add_component(ievent)
return cal.to_ical() return cal.to_ical()

View file

@ -18,9 +18,9 @@ from .ics import gen_ics
############## ical calendar ######################################################## ############## ical calendar ########################################################
class ICSView(View): class ICSView(CampViewMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return HttpResponse(gen_ics(models.Event.objects.all())) return HttpResponse(gen_ics(models.EventInstance.objects.all()))
############## proposals ######################################################## ############## proposals ########################################################