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