1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imiptools/handlers/person_outgoing.py Thu Oct 30 19:08:19 2014 +0100
1.3 @@ -0,0 +1,126 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Handlers for a person for whom scheduling is performed, inspecting outgoing
1.8 +messages to obtain scheduling done externally.
1.9 +"""
1.10 +
1.11 +from imiptools.content import Handler
1.12 +from vCalendar import to_node
1.13 +
1.14 +class PersonHandler(Handler):
1.15 +
1.16 + "Handling mechanisms specific to people."
1.17 +
1.18 + def _record(self, objtype, from_organiser=True, update_freebusy=False):
1.19 + identity = self.get_value(from_organiser and "ORGANIZER" or "ATTENDEE")
1.20 +
1.21 + # Store the object.
1.22 +
1.23 + self.store.set_event(identity, self.uid, to_node(
1.24 + {objtype : [(self.details, {})]}
1.25 + ))
1.26 +
1.27 + # Update free/busy information.
1.28 +
1.29 + if update_freebusy:
1.30 + periods = self.get_periods()
1.31 + freebusy = self.store.get_freebusy(identity) or []
1.32 + self.update_freebusy(freebusy, identity, periods)
1.33 + if self.publisher:
1.34 + self.publisher.set_freebusy(identity, freebusy)
1.35 +
1.36 + return True
1.37 +
1.38 +class Event(PersonHandler):
1.39 +
1.40 + "An event handler."
1.41 +
1.42 + def add(self):
1.43 + pass
1.44 +
1.45 + def cancel(self):
1.46 + pass
1.47 +
1.48 + def counter(self):
1.49 + pass
1.50 +
1.51 + def declinecounter(self):
1.52 + pass
1.53 +
1.54 + def publish(self):
1.55 + self._record("VEVENT", True, True)
1.56 +
1.57 + def refresh(self):
1.58 + self._record("VEVENT", True, True)
1.59 +
1.60 + def reply(self):
1.61 + self._record("VEVENT", False, False)
1.62 +
1.63 + def request(self):
1.64 + self._record("VEVENT", True, True)
1.65 +
1.66 +class Freebusy(PersonHandler):
1.67 +
1.68 + "A free/busy handler."
1.69 +
1.70 + def publish(self):
1.71 + pass
1.72 +
1.73 + def reply(self):
1.74 + pass
1.75 +
1.76 + def request(self):
1.77 + pass
1.78 +
1.79 +class Journal(PersonHandler):
1.80 +
1.81 + "A journal entry handler."
1.82 +
1.83 + def add(self):
1.84 + pass
1.85 +
1.86 + def cancel(self):
1.87 + pass
1.88 +
1.89 + def publish(self):
1.90 + self._record("VJOURNAL", True)
1.91 +
1.92 +class Todo(PersonHandler):
1.93 +
1.94 + "A to-do item handler."
1.95 +
1.96 + def add(self):
1.97 + pass
1.98 +
1.99 + def cancel(self):
1.100 + pass
1.101 +
1.102 + def counter(self):
1.103 + pass
1.104 +
1.105 + def declinecounter(self):
1.106 + pass
1.107 +
1.108 + def publish(self):
1.109 + self._record("VTODO", True)
1.110 +
1.111 + def refresh(self):
1.112 + self._record("VTODO", True)
1.113 +
1.114 + def reply(self):
1.115 + self._record("VTODO", False)
1.116 +
1.117 + def request(self):
1.118 + self._record("VTODO", True)
1.119 +
1.120 +# Handler registry.
1.121 +
1.122 +handlers = [
1.123 + ("VFREEBUSY", Freebusy),
1.124 + ("VEVENT", Event),
1.125 + ("VTODO", Todo),
1.126 + ("VJOURNAL", Journal),
1.127 + ]
1.128 +
1.129 +# vim: tabstop=4 expandtab shiftwidth=4