# HG changeset patch # User Paul Boddie # Date 1443446553 -7200 # Node ID 0036129e8c5357417361c1987995592cd05f5ee2 # Parent a95e76da92c6866b1344384357ea85076c810ae5 Added support for immediate recurrence removal. diff -r a95e76da92c6 -r 0036129e8c53 imipweb/event.py --- a/imipweb/event.py Mon Sep 28 15:22:21 2015 +0200 +++ b/imipweb/event.py Mon Sep 28 15:22:33 2015 +0200 @@ -53,8 +53,20 @@ (None, "Not indicated"), ] - def is_organiser(self): - return get_uri(self.obj.get_value("ORGANIZER")) == self.user + def can_remove_recurrence(self, recurrence): + + """ + Return whether the 'recurrence' can be removed from the current object + without notification. + """ + + return self.recurrence_is_new(recurrence) or not self.obj.is_shared() + + def recurrence_is_new(self, recurrence): + + "Return whether 'recurrence' is new to the current object." + + return recurrence not in self.get_stored_recurrences() def can_remove_attendee(self, attendee): @@ -79,6 +91,9 @@ # Access to stored object information. + def is_organiser(self): + return get_uri(self.obj.get_value("ORGANIZER")) == self.user + def get_stored_attendees(self): return uri_values(self.obj.get_values("ATTENDEE") or []) @@ -374,7 +389,7 @@ # Obtain the periods associated with the event. # NOTE: Add a control to add recurrences here. - recurrences = self.get_current_recurrences() + recurrences = self.update_current_recurrences() if len(recurrences) < 1: return @@ -459,7 +474,7 @@ page.th("") page.td() - remove_type = not self.obj.is_shared() or not period.origin and "submit" or "checkbox" + remove_type = (not self.obj.is_shared() or not period.origin) and "submit" or "checkbox" self.control("recur-remove", remove_type, str(index), str(index) in args.get("recur-remove", []), id="recur-remove-%d" % index, class_="remove") @@ -887,6 +902,37 @@ return attendees + def update_recurrences_from_page(self): + + "Add or remove recurrences. This does not affect the stored object." + + args = self.env.get_args() + + recurrences = self.get_recurrences_from_page() + + # NOTE: Addition of recurrences to be supported. + + # Only actually remove recurrences if the event is unsent, or if the + # recurrence is new. + + if args.has_key("recur-remove"): + still_to_remove = [] + + for i in args["recur-remove"]: + try: + recurrence = recurrences[int(i)] + except IndexError: + continue + + if self.can_remove_recurrence(recurrence): + recurrences.remove(recurrence) + else: + still_to_remove.append(i) + + args["recur-remove"] = still_to_remove + + return recurrences + # Access to current object information. def get_current_main_period(self): @@ -913,6 +959,15 @@ else: return self.get_recurrences_from_page() + def update_current_recurrences(self): + + "Return an updated collection of recurrences for the current object." + + if self.is_initial_load() or not self.is_organiser(): + return self.get_stored_recurrences() + else: + return self.update_recurrences_from_page() + def get_current_attendees(self): """