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@122 | 16 | identity, attr = self.get_item(from_organiser and "ORGANIZER" or "ATTENDEE") |
paul@96 | 17 | |
paul@97 | 18 | # Check for event using UID. |
paul@97 | 19 | |
paul@97 | 20 | if not self.have_new_object(identity, objtype): |
paul@99 | 21 | return False |
paul@97 | 22 | |
paul@96 | 23 | # Store the object. |
paul@96 | 24 | |
paul@96 | 25 | self.store.set_event(identity, self.uid, to_node( |
paul@96 | 26 | {objtype : [(self.details, {})]} |
paul@96 | 27 | )) |
paul@96 | 28 | |
paul@96 | 29 | # Update free/busy information. |
paul@96 | 30 | |
paul@96 | 31 | if update_freebusy: |
paul@97 | 32 | |
paul@97 | 33 | # If newer than any old version, discard old details from the |
paul@97 | 34 | # free/busy record and check for suitability. |
paul@97 | 35 | |
paul@96 | 36 | periods = self.get_periods() |
paul@96 | 37 | freebusy = self.store.get_freebusy(identity) or [] |
paul@97 | 38 | |
paul@122 | 39 | if from_organiser or attr.get("PARTSTAT") == "ACCEPTED": |
paul@122 | 40 | self.update_freebusy(freebusy, identity, periods) |
paul@122 | 41 | else: |
paul@122 | 42 | self.remove_from_freebusy(freebusy, identity) |
paul@97 | 43 | |
paul@96 | 44 | if self.publisher: |
paul@96 | 45 | self.publisher.set_freebusy(identity, freebusy) |
paul@96 | 46 | |
paul@96 | 47 | return True |
paul@96 | 48 | |
paul@96 | 49 | class Event(PersonHandler): |
paul@96 | 50 | |
paul@96 | 51 | "An event handler." |
paul@96 | 52 | |
paul@96 | 53 | def add(self): |
paul@96 | 54 | pass |
paul@96 | 55 | |
paul@96 | 56 | def cancel(self): |
paul@96 | 57 | pass |
paul@96 | 58 | |
paul@96 | 59 | def counter(self): |
paul@96 | 60 | pass |
paul@96 | 61 | |
paul@96 | 62 | def declinecounter(self): |
paul@96 | 63 | pass |
paul@96 | 64 | |
paul@96 | 65 | def publish(self): |
paul@96 | 66 | self._record("VEVENT", True, True) |
paul@96 | 67 | |
paul@96 | 68 | def refresh(self): |
paul@96 | 69 | self._record("VEVENT", True, True) |
paul@96 | 70 | |
paul@96 | 71 | def reply(self): |
paul@99 | 72 | self._record("VEVENT", False, True) |
paul@96 | 73 | |
paul@96 | 74 | def request(self): |
paul@96 | 75 | self._record("VEVENT", True, True) |
paul@96 | 76 | |
paul@96 | 77 | class Freebusy(PersonHandler): |
paul@96 | 78 | |
paul@96 | 79 | "A free/busy handler." |
paul@96 | 80 | |
paul@96 | 81 | def publish(self): |
paul@96 | 82 | pass |
paul@96 | 83 | |
paul@96 | 84 | def reply(self): |
paul@96 | 85 | pass |
paul@96 | 86 | |
paul@96 | 87 | def request(self): |
paul@96 | 88 | pass |
paul@96 | 89 | |
paul@96 | 90 | class Journal(PersonHandler): |
paul@96 | 91 | |
paul@96 | 92 | "A journal entry handler." |
paul@96 | 93 | |
paul@96 | 94 | def add(self): |
paul@96 | 95 | pass |
paul@96 | 96 | |
paul@96 | 97 | def cancel(self): |
paul@96 | 98 | pass |
paul@96 | 99 | |
paul@96 | 100 | def publish(self): |
paul@96 | 101 | self._record("VJOURNAL", True) |
paul@96 | 102 | |
paul@96 | 103 | class Todo(PersonHandler): |
paul@96 | 104 | |
paul@96 | 105 | "A to-do item handler." |
paul@96 | 106 | |
paul@96 | 107 | def add(self): |
paul@96 | 108 | pass |
paul@96 | 109 | |
paul@96 | 110 | def cancel(self): |
paul@96 | 111 | pass |
paul@96 | 112 | |
paul@96 | 113 | def counter(self): |
paul@96 | 114 | pass |
paul@96 | 115 | |
paul@96 | 116 | def declinecounter(self): |
paul@96 | 117 | pass |
paul@96 | 118 | |
paul@96 | 119 | def publish(self): |
paul@96 | 120 | self._record("VTODO", True) |
paul@96 | 121 | |
paul@96 | 122 | def refresh(self): |
paul@96 | 123 | self._record("VTODO", True) |
paul@96 | 124 | |
paul@96 | 125 | def reply(self): |
paul@96 | 126 | self._record("VTODO", False) |
paul@96 | 127 | |
paul@96 | 128 | def request(self): |
paul@96 | 129 | self._record("VTODO", True) |
paul@96 | 130 | |
paul@96 | 131 | # Handler registry. |
paul@96 | 132 | |
paul@96 | 133 | handlers = [ |
paul@96 | 134 | ("VFREEBUSY", Freebusy), |
paul@96 | 135 | ("VEVENT", Event), |
paul@96 | 136 | ("VTODO", Todo), |
paul@96 | 137 | ("VJOURNAL", Journal), |
paul@96 | 138 | ] |
paul@96 | 139 | |
paul@96 | 140 | # vim: tabstop=4 expandtab shiftwidth=4 |