summaryrefslogtreecommitdiffstats
path: root/agenda/icalviews.py
blob: 5081365c6b78762f1678fbaa0afa456b5d7c7860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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