diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-07-07 21:36:59 -0400 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-07-07 21:36:59 -0400 |
commit | ebcc6748bf105fda1183bce3242260b867271809 (patch) | |
tree | b7e92eb9e00197f1b6c9ae9b5c897c0c7fa01aab | |
parent | e6ee15781cf3a3a8d0606351683438a5281e6530 (diff) | |
download | pykolab-ebcc6748bf105fda1183bce3242260b867271809.tar.gz |
Simplify code, get rid of exec() calls; allow to set RSVP flag wen updtading a participant's status
-rw-r--r-- | pykolab/xml/event.py | 41 | ||||
-rw-r--r-- | wallace/module_invitationpolicy.py | 2 |
2 files changed, 24 insertions, 19 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py index f9b6487..65eb818 100644 --- a/pykolab/xml/event.py +++ b/pykolab/xml/event.py @@ -126,29 +126,31 @@ class Event(object): # NOTE: Make sure to list(set()) or duplicates may arise for attr in list(set(event.singletons)): - if hasattr(self, 'get_ical_%s' % (attr.lower())): - exec("retval = self.get_ical_%s()" % (attr.lower())) + ical_getter = 'get_ical_%s' % (attr.lower()) + default_getter = 'get_%s' % (attr.lower()) + retval = None + if hasattr(self, ical_getter): + retval = getattr(self, ical_getter)() if not retval == None and not retval == "": event.add(attr.lower(), retval) - - elif hasattr(self, 'get_%s' % (attr.lower())): - exec("retval = self.get_%s()" % (attr.lower())) + elif hasattr(self, default_getter): + retval = getattr(self, default_getter)() if not retval == None and not retval == "": event.add(attr.lower(), retval, encode=0) # NOTE: Make sure to list(set()) or duplicates may arise for attr in list(set(event.multiple)): - if hasattr(self, 'get_ical_%s' % (attr.lower())): - exec("retval = self.get_ical_%s()" % (attr.lower())) - if isinstance(retval, list) and not len(retval) == 0: - for _retval in retval: - event.add(attr.lower(), _retval, encode=0) - - elif hasattr(self, 'get_%s' % (attr.lower())): - exec("retval = self.get_%s()" % (attr.lower())) - if isinstance(retval, list) and not len(retval) == 0: - for _retval in retval: - event.add(attr.lower(), _retval, encode=0) + ical_getter = 'get_ical_%s' % (attr.lower()) + default_getter = 'get_%s' % (attr.lower()) + retval = None + if hasattr(self, ical_getter): + retval = getattr(self, ical_getter)() + elif hasattr(self, default_getter): + retval = getattr(self, default_getter)() + + if isinstance(retval, list) and not len(retval) == 0: + for _retval in retval: + event.add(attr.lower(), _retval, encode=0) cal.add_component(event) @@ -491,7 +493,7 @@ class Event(object): def get_transparency(self): return self.event.transparency() - def set_attendee_participant_status(self, attendee, status): + def set_attendee_participant_status(self, attendee, status, rsvp=None): """ Set the participant status of an attendee to status. @@ -500,8 +502,11 @@ class Event(object): attendees for this event. """ attendee = self.get_attendee(attendee) - attendee.set_participant_status(status) + + if rsvp is not None: + attendee.set_rsvp(rsvp) + self.event.setAttendees(self._attendees) def set_status(self, status): diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py index 9488dd1..ec3ad44 100644 --- a/wallace/module_invitationpolicy.py +++ b/wallace/module_invitationpolicy.py @@ -419,7 +419,7 @@ def process_itip_reply(itip_event, policy, recipient_email, sender_email, receiv log.debug(_("Auto-updating event %r on iTip REPLY") % (existing.uid), level=8) try: - existing.set_attendee_participant_status(sender_email, sender_attendee.get_participant_status(), False) + existing.set_attendee_participant_status(sender_email, sender_attendee.get_participant_status(), rsvp=False) except Exception, e: log.error("Could not find corresponding attende in organizer's event: %r" % (e)) |