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