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