Agenda
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / savoirs / lib / calendrier.py
CommitLineData
92c7413b
CR
1# -*- encoding: utf-8 -*-
2import caldav, datetime, time, pytz
3from savoirs import configuration
4
5def evenements():
6 rc = []
7
8 client = caldav.DAVClient(configuration['calendrier'])
9 cal = caldav.Calendar(client, url = configuration['calendrier'])
10 start = datetime.datetime.now().strftime("%Y%m%dT%H%M%S%z")
11 events = cal.date_search(start)
12
13 for e in events:
14 rc.append(e.instance.vevent)
15
16 rc.sort(lambda x,y: cmp(time.mktime(x.dtstart.value.timetuple()),
17 time.mktime(y.dtstart.value.timetuple())))
18
19 return rc
20
21
22
23def evenement_info(uid):
24 client = caldav.DAVClient(configuration['calendrier'])
25 cal = caldav.Calendar(client, url = configuration['calendrier'])
26 return cal.event(uid)
27
28def evenement_publie(event):
29 client = caldav.DAVClient(configuration['calendrier'])
30 cal = caldav.Calendar(client, url = configuration['calendrier'])
31 e = caldav.Event(client, parent = cal, data = event.serialize()).save()
32
33def combine(when, tz):
34 r = datetime.datetime(when.year, when.month, when.day,
35 when.hour, when.minute, tzinfo = pytz.timezone(tz))
36 #r = r.replace(tzinfo = pytz.timezone("UTC"))
37 t = r.utctimetuple()
38 r = datetime.datetime(*(t[0:6]), tzinfo = pytz.timezone("UTC"))
39 return r