adapt ics code to work with eventinstances instead of the old event.days system
This commit is contained in:
parent
33689c5270
commit
35f22bdb71
|
@ -1,25 +1,13 @@
|
|||
import icalendar
|
||||
from icalendar import vDatetime
|
||||
|
||||
|
||||
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):
|
||||
def gen_ics(eventinstances):
|
||||
cal = icalendar.Calendar()
|
||||
for event in events:
|
||||
for ical_event in gen_icalevents(event):
|
||||
cal.add_component(ical_event)
|
||||
for eventinstance in eventinstances:
|
||||
ievent = icalendar.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()
|
||||
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ from .ics import gen_ics
|
|||
############## ical calendar ########################################################
|
||||
|
||||
|
||||
class ICSView(View):
|
||||
class ICSView(CampViewMixin, View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return HttpResponse(gen_ics(models.Event.objects.all()))
|
||||
return HttpResponse(gen_ics(models.EventInstance.objects.all()))
|
||||
|
||||
|
||||
############## proposals ########################################################
|
||||
|
|
Loading…
Reference in a new issue