CRUD evenement + admin
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / savoirs / lib / calendrier.py
CommitLineData
92c7413b
CR
1# -*- encoding: utf-8 -*-
2import caldav, datetime, time, pytz
ecc62927 3from savoirs.globals import configuration
669b7444 4from settings import CALENDRIER_URL
92c7413b
CR
5
6def evenements():
7 rc = []
8
669b7444 9 client = caldav.DAVClient(CALENDRIER_URL)
10 cal = caldav.Calendar(client, url = CALENDRIER_URL)
17369944 11 start = datetime.datetime.now()
92c7413b
CR
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
92c7413b 22def evenement_info(uid):
669b7444 23 client = caldav.DAVClient(CALENDRIER_URL)
24 cal = caldav.Calendar(client, url = CALENDRIER_URL)
92c7413b
CR
25 return cal.event(uid)
26
92c7413b
CR
27
28def combine(when, tz):
29 r = datetime.datetime(when.year, when.month, when.day,
b7a741ad 30 when.hour, when.minute, tzinfo = pytz.timezone(unicode(tz)))
92c7413b
CR
31 #r = r.replace(tzinfo = pytz.timezone("UTC"))
32 t = r.utctimetuple()
1f3ab4fa
CR
33 r = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],
34 tzinfo = pytz.timezone("UTC"))
92c7413b 35 return r