paul@96 | 1 | #!/usr/bin/env python |
paul@96 | 2 | |
paul@96 | 3 | """ |
paul@96 | 4 | Handlers for a person for whom scheduling is performed, inspecting outgoing |
paul@96 | 5 | messages to obtain scheduling done externally. |
paul@96 | 6 | """ |
paul@96 | 7 | |
paul@96 | 8 | from imiptools.content import Handler |
paul@96 | 9 | from vCalendar import to_node |
paul@96 | 10 | |
paul@96 | 11 | class PersonHandler(Handler): |
paul@96 | 12 | |
paul@96 | 13 | "Handling mechanisms specific to people." |
paul@96 | 14 | |
paul@96 | 15 | def _record(self, objtype, from_organiser=True, update_freebusy=False): |
paul@96 | 16 | identity = self.get_value(from_organiser and "ORGANIZER" or "ATTENDEE") |
paul@96 | 17 | |
paul@96 | 18 | # Store the object. |
paul@96 | 19 | |
paul@96 | 20 | self.store.set_event(identity, self.uid, to_node( |
paul@96 | 21 | {objtype : [(self.details, {})]} |
paul@96 | 22 | )) |
paul@96 | 23 | |
paul@96 | 24 | # Update free/busy information. |
paul@96 | 25 | |
paul@96 | 26 | if update_freebusy: |
paul@96 | 27 | periods = self.get_periods() |
paul@96 | 28 | freebusy = self.store.get_freebusy(identity) or [] |
paul@96 | 29 | self.update_freebusy(freebusy, identity, periods) |
paul@96 | 30 | if self.publisher: |
paul@96 | 31 | self.publisher.set_freebusy(identity, freebusy) |
paul@96 | 32 | |
paul@96 | 33 | return True |
paul@96 | 34 | |
paul@96 | 35 | class Event(PersonHandler): |
paul@96 | 36 | |
paul@96 | 37 | "An event handler." |
paul@96 | 38 | |
paul@96 | 39 | def add(self): |
paul@96 | 40 | pass |
paul@96 | 41 | |
paul@96 | 42 | def cancel(self): |
paul@96 | 43 | pass |
paul@96 | 44 | |
paul@96 | 45 | def counter(self): |
paul@96 | 46 | pass |
paul@96 | 47 | |
paul@96 | 48 | def declinecounter(self): |
paul@96 | 49 | pass |
paul@96 | 50 | |
paul@96 | 51 | def publish(self): |
paul@96 | 52 | self._record("VEVENT", True, True) |
paul@96 | 53 | |
paul@96 | 54 | def refresh(self): |
paul@96 | 55 | self._record("VEVENT", True, True) |
paul@96 | 56 | |
paul@96 | 57 | def reply(self): |
paul@96 | 58 | self._record("VEVENT", False, False) |
paul@96 | 59 | |
paul@96 | 60 | def request(self): |
paul@96 | 61 | self._record("VEVENT", True, True) |
paul@96 | 62 | |
paul@96 | 63 | class Freebusy(PersonHandler): |
paul@96 | 64 | |
paul@96 | 65 | "A free/busy handler." |
paul@96 | 66 | |
paul@96 | 67 | def publish(self): |
paul@96 | 68 | pass |
paul@96 | 69 | |
paul@96 | 70 | def reply(self): |
paul@96 | 71 | pass |
paul@96 | 72 | |
paul@96 | 73 | def request(self): |
paul@96 | 74 | pass |
paul@96 | 75 | |
paul@96 | 76 | class Journal(PersonHandler): |
paul@96 | 77 | |
paul@96 | 78 | "A journal entry handler." |
paul@96 | 79 | |
paul@96 | 80 | def add(self): |
paul@96 | 81 | pass |
paul@96 | 82 | |
paul@96 | 83 | def cancel(self): |
paul@96 | 84 | pass |
paul@96 | 85 | |
paul@96 | 86 | def publish(self): |
paul@96 | 87 | self._record("VJOURNAL", True) |
paul@96 | 88 | |
paul@96 | 89 | class Todo(PersonHandler): |
paul@96 | 90 | |
paul@96 | 91 | "A to-do item handler." |
paul@96 | 92 | |
paul@96 | 93 | def add(self): |
paul@96 | 94 | pass |
paul@96 | 95 | |
paul@96 | 96 | def cancel(self): |
paul@96 | 97 | pass |
paul@96 | 98 | |
paul@96 | 99 | def counter(self): |
paul@96 | 100 | pass |
paul@96 | 101 | |
paul@96 | 102 | def declinecounter(self): |
paul@96 | 103 | pass |
paul@96 | 104 | |
paul@96 | 105 | def publish(self): |
paul@96 | 106 | self._record("VTODO", True) |
paul@96 | 107 | |
paul@96 | 108 | def refresh(self): |
paul@96 | 109 | self._record("VTODO", True) |
paul@96 | 110 | |
paul@96 | 111 | def reply(self): |
paul@96 | 112 | self._record("VTODO", False) |
paul@96 | 113 | |
paul@96 | 114 | def request(self): |
paul@96 | 115 | self._record("VTODO", True) |
paul@96 | 116 | |
paul@96 | 117 | # Handler registry. |
paul@96 | 118 | |
paul@96 | 119 | handlers = [ |
paul@96 | 120 | ("VFREEBUSY", Freebusy), |
paul@96 | 121 | ("VEVENT", Event), |
paul@96 | 122 | ("VTODO", Todo), |
paul@96 | 123 | ("VJOURNAL", Journal), |
paul@96 | 124 | ] |
paul@96 | 125 | |
paul@96 | 126 | # vim: tabstop=4 expandtab shiftwidth=4 |