paul@55 | 1 | #!/usr/bin/env python |
paul@55 | 2 | |
paul@55 | 3 | """ |
paul@55 | 4 | Handlers for a person for whom scheduling is performed. |
paul@55 | 5 | """ |
paul@55 | 6 | |
paul@55 | 7 | from imiptools.content import Handler |
paul@55 | 8 | from vCalendar import to_node |
paul@55 | 9 | |
paul@55 | 10 | class Event(Handler): |
paul@55 | 11 | |
paul@55 | 12 | "An event handler." |
paul@55 | 13 | |
paul@55 | 14 | def add(self): |
paul@55 | 15 | pass |
paul@55 | 16 | |
paul@55 | 17 | def cancel(self): |
paul@55 | 18 | pass |
paul@55 | 19 | |
paul@55 | 20 | def counter(self): |
paul@55 | 21 | |
paul@55 | 22 | "Since this handler does not send requests, it will not handle replies." |
paul@55 | 23 | |
paul@55 | 24 | pass |
paul@55 | 25 | |
paul@55 | 26 | def declinecounter(self): |
paul@55 | 27 | |
paul@55 | 28 | """ |
paul@55 | 29 | Since this handler does not send counter proposals, it will not handle |
paul@55 | 30 | replies to such proposals. |
paul@55 | 31 | """ |
paul@55 | 32 | |
paul@55 | 33 | pass |
paul@55 | 34 | |
paul@55 | 35 | def publish(self): |
paul@55 | 36 | pass |
paul@55 | 37 | |
paul@55 | 38 | def refresh(self): |
paul@55 | 39 | pass |
paul@55 | 40 | |
paul@55 | 41 | def reply(self): |
paul@55 | 42 | |
paul@55 | 43 | "Since this handler does not send requests, it will not handle replies." |
paul@55 | 44 | |
paul@55 | 45 | pass |
paul@55 | 46 | |
paul@55 | 47 | def request(self): |
paul@55 | 48 | |
paul@55 | 49 | "Hold requests and notify the recipient." |
paul@55 | 50 | |
paul@55 | 51 | oa = self.require_organiser_and_attendees() |
paul@55 | 52 | if not oa: |
paul@55 | 53 | return None |
paul@55 | 54 | |
paul@55 | 55 | (organiser, organiser_attr), attendees = oa |
paul@55 | 56 | |
paul@55 | 57 | # Process each attendee separately. |
paul@55 | 58 | |
paul@55 | 59 | for attendee, attendee_attr in attendees.items(): |
paul@55 | 60 | |
paul@55 | 61 | if not self.have_new_object(attendee, "VEVENT"): |
paul@55 | 62 | continue |
paul@55 | 63 | |
paul@55 | 64 | # Store the event and queue the request. |
paul@55 | 65 | |
paul@55 | 66 | self.store.set_event(attendee, self.uid, to_node( |
paul@55 | 67 | {"VEVENT" : [(self.details, {})]} |
paul@55 | 68 | )) |
paul@55 | 69 | |
paul@55 | 70 | self.store.queue_request(attendee, self.uid) |
paul@55 | 71 | |
paul@55 | 72 | # The message is now wrapped and passed on to the recipient. |
paul@55 | 73 | |
paul@55 | 74 | class Freebusy(Handler): |
paul@55 | 75 | |
paul@55 | 76 | "A free/busy handler." |
paul@55 | 77 | |
paul@55 | 78 | def publish(self): |
paul@55 | 79 | pass |
paul@55 | 80 | |
paul@55 | 81 | def reply(self): |
paul@55 | 82 | |
paul@55 | 83 | "Since this handler does not send requests, it will not handle replies." |
paul@55 | 84 | |
paul@55 | 85 | pass |
paul@55 | 86 | |
paul@55 | 87 | def request(self): |
paul@55 | 88 | |
paul@55 | 89 | """ |
paul@55 | 90 | Respond to a request by preparing a reply containing free/busy |
paul@55 | 91 | information for each indicated attendee. |
paul@55 | 92 | """ |
paul@55 | 93 | |
paul@55 | 94 | # NOTE: This is currently the same as the resource handler but should be |
paul@55 | 95 | # NOTE: subject to policy/preferences. |
paul@55 | 96 | |
paul@55 | 97 | oa = self.require_organiser_and_attendees() |
paul@55 | 98 | if not oa: |
paul@55 | 99 | return None |
paul@55 | 100 | |
paul@55 | 101 | (organiser, organiser_attr), attendees = oa |
paul@55 | 102 | |
paul@55 | 103 | # Construct an appropriate fragment. |
paul@55 | 104 | |
paul@55 | 105 | calendar = [] |
paul@55 | 106 | cwrite = calendar.append |
paul@55 | 107 | |
paul@55 | 108 | # Get the details for each attendee. |
paul@55 | 109 | |
paul@55 | 110 | for attendee, attendee_attr in attendees.items(): |
paul@55 | 111 | freebusy = self.store.get_freebusy(attendee) |
paul@55 | 112 | |
paul@55 | 113 | if freebusy: |
paul@55 | 114 | record = [] |
paul@55 | 115 | rwrite = record.append |
paul@55 | 116 | |
paul@55 | 117 | rwrite(("ORGANIZER", organiser_attr, organiser)) |
paul@55 | 118 | rwrite(("ATTENDEE", attendee_attr, attendee)) |
paul@55 | 119 | rwrite(("UID", {}, self.uid)) |
paul@55 | 120 | |
paul@55 | 121 | for start, end, uid in freebusy: |
paul@55 | 122 | rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, [start, end])) |
paul@55 | 123 | |
paul@55 | 124 | cwrite(("VFREEBUSY", {}, record)) |
paul@55 | 125 | |
paul@55 | 126 | # Return the reply. |
paul@55 | 127 | |
paul@55 | 128 | return calendar |
paul@55 | 129 | |
paul@55 | 130 | class Journal(Handler): |
paul@55 | 131 | |
paul@55 | 132 | "A journal entry handler." |
paul@55 | 133 | |
paul@55 | 134 | def add(self): |
paul@55 | 135 | pass |
paul@55 | 136 | |
paul@55 | 137 | def cancel(self): |
paul@55 | 138 | pass |
paul@55 | 139 | |
paul@55 | 140 | def publish(self): |
paul@55 | 141 | pass |
paul@55 | 142 | |
paul@55 | 143 | class Todo(Handler): |
paul@55 | 144 | |
paul@55 | 145 | "A to-do item handler." |
paul@55 | 146 | |
paul@55 | 147 | def add(self): |
paul@55 | 148 | pass |
paul@55 | 149 | |
paul@55 | 150 | def cancel(self): |
paul@55 | 151 | pass |
paul@55 | 152 | |
paul@55 | 153 | def counter(self): |
paul@55 | 154 | |
paul@55 | 155 | "Since this handler does not send requests, it will not handle replies." |
paul@55 | 156 | |
paul@55 | 157 | pass |
paul@55 | 158 | |
paul@55 | 159 | def declinecounter(self): |
paul@55 | 160 | |
paul@55 | 161 | """ |
paul@55 | 162 | Since this handler does not send counter proposals, it will not handle |
paul@55 | 163 | replies to such proposals. |
paul@55 | 164 | """ |
paul@55 | 165 | |
paul@55 | 166 | pass |
paul@55 | 167 | |
paul@55 | 168 | def publish(self): |
paul@55 | 169 | pass |
paul@55 | 170 | |
paul@55 | 171 | def refresh(self): |
paul@55 | 172 | pass |
paul@55 | 173 | |
paul@55 | 174 | def reply(self): |
paul@55 | 175 | |
paul@55 | 176 | "Since this handler does not send requests, it will not handle replies." |
paul@55 | 177 | |
paul@55 | 178 | pass |
paul@55 | 179 | |
paul@55 | 180 | def request(self): |
paul@55 | 181 | pass |
paul@55 | 182 | |
paul@55 | 183 | # Handler registry. |
paul@55 | 184 | |
paul@55 | 185 | handlers = [ |
paul@55 | 186 | ("VFREEBUSY", Freebusy), |
paul@55 | 187 | ("VEVENT", Event), |
paul@55 | 188 | ("VTODO", Todo), |
paul@55 | 189 | ("VJOURNAL", Journal), |
paul@55 | 190 | ] |
paul@55 | 191 | |
paul@55 | 192 | # vim: tabstop=4 expandtab shiftwidth=4 |