hand merge and commit PR #76
This commit is contained in:
commit
3cc2f21bfb
|
@ -231,6 +231,11 @@ urlpatterns = [
|
|||
EventDetailView.as_view(),
|
||||
name='event_detail'
|
||||
),
|
||||
url(
|
||||
r'^calendar/',
|
||||
ICSView.as_view(),
|
||||
name='ics_calendar'
|
||||
),
|
||||
])
|
||||
),
|
||||
|
||||
|
|
|
@ -12,6 +12,36 @@ from camps.mixins import CampViewMixin
|
|||
from .mixins import CreateProposalMixin, EnsureUnapprovedProposalMixin, EnsureUserOwnsProposalMixin, EnsureWritableCampMixin, PictureViewMixin, EnsureCFSOpenMixin
|
||||
from . import models
|
||||
import datetime, os
|
||||
import icalendar
|
||||
from icalendar import vDatetime
|
||||
|
||||
|
||||
############## ical calendar ########################################################
|
||||
|
||||
|
||||
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()
|
||||
for event in events:
|
||||
for ical_event in gen_icalevents(event):
|
||||
cal.add_component(ical_event)
|
||||
return cal.to_ical()
|
||||
|
||||
class ICSView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return HttpResponse(gen_ics(models.Event.objects.all()))
|
||||
|
||||
|
||||
############## proposals ########################################################
|
||||
|
|
|
@ -16,6 +16,7 @@ django-wkhtmltopdf==3.1.0
|
|||
docopt==0.6.2
|
||||
future==0.16.0
|
||||
html5lib==0.9999999
|
||||
icalendar==3.11.3
|
||||
ipython==5.3.0
|
||||
irc3==0.9.8
|
||||
oauthlib==2.0.1
|
||||
|
|
Loading…
Reference in a new issue