# HG changeset patch # User Paul Boddie # Date 1432127193 -7200 # Node ID 4a707cba0ae75e057351b3aed6d242da385952aa # Parent 1f47884f8d96978c22dbd23cfb73ac16c8d2a186 Moved participation modification into a common client method. diff -r 1f47884f8d96 -r 4a707cba0ae7 imiptools/client.py --- a/imiptools/client.py Wed May 20 13:41:23 2015 +0200 +++ b/imiptools/client.py Wed May 20 15:06:33 2015 +0200 @@ -19,7 +19,7 @@ this program. If not, see . """ -from imiptools.data import get_uri, get_window_end, uri_dict, uri_items, uri_values +from imiptools.data import get_address, get_uri, get_window_end, uri_dict, uri_items, uri_values from imiptools.dates import get_default_timezone from imiptools.profile import Preferences @@ -66,18 +66,6 @@ return to_cancel -def update_participation(obj, user, partstat): - - "Update the participation in 'obj' of 'user' with the given 'partstat'." - - existing_attendees = uri_dict(obj.get_value_map("ATTENDEE")) - - if partstat: - if existing_attendees.has_key(user): - existing_attendees[user]["PARTSTAT"] = partstat - if existing_attendees[user].has_key("RSVP"): - del existing_attendees[user]["RSVP"] - class Client: "Common handler and manager methods." @@ -119,4 +107,20 @@ prefs = self.get_preferences() return prefs and prefs.get("freebusy_messages") == "notify" or False + # Common operations on calendar data. + + def update_participation(self, obj, partstat): + + """ + Update the participation in 'obj' of the user with the given 'partstat'. + """ + + attendee_attr = uri_dict(obj.get_value_map("ATTENDEE")).get(self.user) + attendee_attr["PARTSTAT"] = partstat + if attendee_attr.has_key("RSVP"): + del attendee_attr["RSVP"] + if self.messenger and self.messenger.sender != get_address(self.user): + attendee_attr["SENT-BY"] = get_uri(self.messenger.sender) + return attendee_attr + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 1f47884f8d96 -r 4a707cba0ae7 imiptools/handlers/resource.py --- a/imiptools/handlers/resource.py Wed May 20 13:41:23 2015 +0200 +++ b/imiptools/handlers/resource.py Wed May 20 15:06:33 2015 +0200 @@ -19,7 +19,7 @@ this program. If not, see . """ -from imiptools.data import get_address, get_uri, to_part +from imiptools.data import get_address, to_part from imiptools.handlers import Handler from imiptools.handlers.common import CommonFreebusy, Outgoing @@ -27,18 +27,6 @@ "Handling mechanisms specific to resources." - def set_participation(self, scheduled): - - "Set the user's participation in the current object if 'scheduled'." - - attendee_attr = self.obj.get_value_map("ATTENDEE").get(self.user) - attendee_attr["PARTSTAT"] = scheduled and "ACCEPTED" or "DECLINED" - if attendee_attr.has_key("RSVP"): - del attendee_attr["RSVP"] - if self.messenger and self.messenger.sender != get_address(self.user): - attendee_attr["SENT-BY"] = get_uri(self.messenger.sender) - return attendee_attr - def _record_and_respond(self, handle_for_attendee): """ @@ -89,7 +77,8 @@ # Update the participation of the resource in the object. - attendee_attr = self.set_participation(scheduled) + attendee_attr = self.update_participation(self.obj, + scheduled and "ACCEPTED" or "DECLINED") # Set the complete event or an additional occurrence. diff -r 1f47884f8d96 -r 4a707cba0ae7 imipweb/event.py --- a/imipweb/event.py Wed May 20 13:41:23 2015 +0200 +++ b/imipweb/event.py Wed May 20 15:06:33 2015 +0200 @@ -20,7 +20,7 @@ """ from datetime import date, timedelta -from imiptools.client import update_attendees, update_participation +from imiptools.client import update_attendees from imiptools.data import get_uri, uri_dict, uri_values from imiptools.dates import format_datetime, get_datetime_item, \ get_period_item, to_date, to_timezone @@ -143,10 +143,10 @@ to_cancel = update_attendees(obj, attendees, removed) single_user = not attendees or attendees == [self.user] - # Update attendee participation. + # Update attendee participation for the current user. if args.has_key("partstat"): - update_participation(obj, self.user, args["partstat"][0]) + self.update_participation(obj, args["partstat"][0]) # Process any action.