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