summaryrefslogtreecommitdiffstats
path: root/agenda/icalviews.py
diff options
context:
space:
mode:
Diffstat (limited to 'agenda/icalviews.py')
-rw-r--r--agenda/icalviews.py109
1 files changed, 109 insertions, 0 deletions
diff --git a/agenda/icalviews.py b/agenda/icalviews.py
new file mode 100644
index 0000000..5081365
--- /dev/null
+++ b/agenda/icalviews.py
@@ -0,0 +1,109 @@
+# vim: ai ts=4 sts=4 et sw=4
+# Create your views here.
+from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
+from infopoint.agenda.models import *
+from datetime import date
+from django.http import HttpResponse, HttpResponseRedirect
+from django.contrib.contenttypes.models import ContentType
+from django.contrib.auth import authenticate, login
+from django.contrib.auth.models import Group,User
+from django.contrib.comments.models import Comment
+from infopoint.agenda.templatetags import *
+from django.contrib.formtools.preview import FormPreview
+from django.views.generic import create_update
+from django.template import RequestContext
+from django.forms import ModelForm
+import pydot,vobject
+
+today = date.today()
+
+EVENT_ITEMS = (
+ ('uid', 'uid'),
+ ('dtstart', 'start'),
+ ('dtend', 'end'),
+ ('summary', 'summary'),
+ ('status', 'status'),
+ ('location', 'location'),
+ ('last_modified', 'last_modified'),
+ ('created', 'created'),
+)
+
+class ICalendarFeed(object):
+ def __call__(self, *args, **kwargs):
+ cal = vobject.iCalendar()
+ for item in self.items():
+ event = cal.add('vevent')
+ for vkey, key in EVENT_ITEMS:
+ value = getattr(self, 'item_' + key)(item)
+ if value:
+ event.add(vkey).value = value
+ event.add('TRANSP').value = 'OPAQUE'
+
+
+ return cal
+
+ def items(self):
+ return []
+
+ def item_status(self, item):
+ pass
+
+ def item_uid(self, item):
+ pass
+
+ def item_start(self, item):
+ pass
+
+ def item_end(self, item):
+ pass
+
+ def item_summary(self, item):
+ return str(item)
+
+ def item_location(self, item):
+ pass
+
+ def item_last_modified(self, item):
+ pass
+
+ def item_created(self, item):
+ pass
+
+
+class SomeEventCalendar(ICalendarFeed):
+ def items(self):
+ return Event.events.next_events()
+
+ def item_uid(self, item):
+ return str(item.id)
+
+ def item_start(self, item):
+ return item.start_date
+
+ def item_summary(self, item):
+ return "%s - %s" % (item.title, item.description)
+
+ def item_location(self, item):
+ return item.location.title
+
+ def item_status(self, item):
+ if item.confirmed == 1:
+ return "CONFIRMED"
+ else:
+ return "PENDING"
+
+
+ def item_end(self, item):
+ return item.end_date
+
+
+def user_freebusy(request,user_id):
+ event_list = Event.events.next_events().select_related()
+ ical = SomeEventCalendar()
+ ical.items = Event.events.next_events()
+ response = HttpResponse(ical.serialize())
+ response['Content-Type'] = 'text/calendar'
+ response['Filename'] = 'filename.ics' # IE needs this
+ response['Content-Disposition'] = 'attachment; filename=filename.ics'
+ return response
+