7724606d402aab6ac889d70c572847b867182f9b
[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
23
24 def evenement_info(uid):
25 client = caldav.DAVClient(CALENDRIER_URL)
26 cal = caldav.Calendar(client, url = CALENDRIER_URL)
27 return cal.event(uid)
28
29 def evenement_publie(event):
30 client = caldav.DAVClient(CALENDRIER_URL)
31 cal = caldav.Calendar(client, url = CALENDRIER_URL)
32 e = caldav.Event(client, parent = cal, data = event.serialize()).save()
33
34 def combine(when, tz):
35 r = datetime.datetime(when.year, when.month, when.day,
36 when.hour, when.minute, tzinfo = pytz.timezone(tz))
37 #r = r.replace(tzinfo = pytz.timezone("UTC"))
38 t = r.utctimetuple()
39 r = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],
40 tzinfo = pytz.timezone("UTC"))
41 return r