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 = self.get_value(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 self.update_freebusy(freebusy, identity, periods) 40 41 if self.publisher: 42 self.publisher.set_freebusy(identity, freebusy) 43 44 return True 45 46 class Event(PersonHandler): 47 48 "An event handler." 49 50 def add(self): 51 pass 52 53 def cancel(self): 54 pass 55 56 def counter(self): 57 pass 58 59 def declinecounter(self): 60 pass 61 62 def publish(self): 63 self._record("VEVENT", True, True) 64 65 def refresh(self): 66 self._record("VEVENT", True, True) 67 68 def reply(self): 69 self._record("VEVENT", False, True) 70 71 def request(self): 72 self._record("VEVENT", True, True) 73 74 class Freebusy(PersonHandler): 75 76 "A free/busy handler." 77 78 def publish(self): 79 pass 80 81 def reply(self): 82 pass 83 84 def request(self): 85 pass 86 87 class Journal(PersonHandler): 88 89 "A journal entry handler." 90 91 def add(self): 92 pass 93 94 def cancel(self): 95 pass 96 97 def publish(self): 98 self._record("VJOURNAL", True) 99 100 class Todo(PersonHandler): 101 102 "A to-do item handler." 103 104 def add(self): 105 pass 106 107 def cancel(self): 108 pass 109 110 def counter(self): 111 pass 112 113 def declinecounter(self): 114 pass 115 116 def publish(self): 117 self._record("VTODO", True) 118 119 def refresh(self): 120 self._record("VTODO", True) 121 122 def reply(self): 123 self._record("VTODO", False) 124 125 def request(self): 126 self._record("VTODO", True) 127 128 # Handler registry. 129 130 handlers = [ 131 ("VFREEBUSY", Freebusy), 132 ("VEVENT", Event), 133 ("VTODO", Todo), 134 ("VJOURNAL", Journal), 135 ] 136 137 # vim: tabstop=4 expandtab shiftwidth=4