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 # Store the object. 19 20 self.store.set_event(identity, self.uid, to_node( 21 {objtype : [(self.details, {})]} 22 )) 23 24 # Update free/busy information. 25 26 if update_freebusy: 27 periods = self.get_periods() 28 freebusy = self.store.get_freebusy(identity) or [] 29 self.update_freebusy(freebusy, identity, periods) 30 if self.publisher: 31 self.publisher.set_freebusy(identity, freebusy) 32 33 return True 34 35 class Event(PersonHandler): 36 37 "An event handler." 38 39 def add(self): 40 pass 41 42 def cancel(self): 43 pass 44 45 def counter(self): 46 pass 47 48 def declinecounter(self): 49 pass 50 51 def publish(self): 52 self._record("VEVENT", True, True) 53 54 def refresh(self): 55 self._record("VEVENT", True, True) 56 57 def reply(self): 58 self._record("VEVENT", False, False) 59 60 def request(self): 61 self._record("VEVENT", True, True) 62 63 class Freebusy(PersonHandler): 64 65 "A free/busy handler." 66 67 def publish(self): 68 pass 69 70 def reply(self): 71 pass 72 73 def request(self): 74 pass 75 76 class Journal(PersonHandler): 77 78 "A journal entry handler." 79 80 def add(self): 81 pass 82 83 def cancel(self): 84 pass 85 86 def publish(self): 87 self._record("VJOURNAL", True) 88 89 class Todo(PersonHandler): 90 91 "A to-do item handler." 92 93 def add(self): 94 pass 95 96 def cancel(self): 97 pass 98 99 def counter(self): 100 pass 101 102 def declinecounter(self): 103 pass 104 105 def publish(self): 106 self._record("VTODO", True) 107 108 def refresh(self): 109 self._record("VTODO", True) 110 111 def reply(self): 112 self._record("VTODO", False) 113 114 def request(self): 115 self._record("VTODO", True) 116 117 # Handler registry. 118 119 handlers = [ 120 ("VFREEBUSY", Freebusy), 121 ("VEVENT", Event), 122 ("VTODO", Todo), 123 ("VJOURNAL", Journal), 124 ] 125 126 # vim: tabstop=4 expandtab shiftwidth=4