CRUD evenement + admin
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / savoirs / lib / calendrier.py
1 # -*- encoding: utf-8 -*-
2 import caldav, datetime, time, pytz
3 from savoirs.globals import configuration
4 from settings import CALENDRIER_URL
5
6 def evenements():
7 rc = []
8
9 client = caldav.DAVClient(CALENDRIER_URL)
10 cal = caldav.Calendar(client, url = CALENDRIER_URL)
11 start = datetime.datetime.now()
12 events = cal.date_search(start)
13
14 for e in events:
15 rc.append(e.instance.vevent)
16
17 rc.sort(lambda x,y: cmp(time.mktime(x.dtstart.value.timetuple()),
18 time.mktime(y.dtstart.value.timetuple())))
19
20 return rc
21
22 def evenement_info(uid):
23 client = caldav.DAVClient(CALENDRIER_URL)
24 cal = caldav.Calendar(client, url = CALENDRIER_URL)
25 return cal.event(uid)
26
27
28 def combine(when, tz):
29 r = datetime.datetime(when.year, when.month, when.day,
30 when.hour, when.minute, tzinfo = pytz.timezone(unicode(tz)))
31 #r = r.replace(tzinfo = pytz.timezone("UTC"))
32 t = r.utctimetuple()
33 r = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],
34 tzinfo = pytz.timezone("UTC"))
35 return r