1.1 --- a/imipweb/event.py Mon Sep 28 15:22:21 2015 +0200
1.2 +++ b/imipweb/event.py Mon Sep 28 15:22:33 2015 +0200
1.3 @@ -53,8 +53,20 @@
1.4 (None, "Not indicated"),
1.5 ]
1.6
1.7 - def is_organiser(self):
1.8 - return get_uri(self.obj.get_value("ORGANIZER")) == self.user
1.9 + def can_remove_recurrence(self, recurrence):
1.10 +
1.11 + """
1.12 + Return whether the 'recurrence' can be removed from the current object
1.13 + without notification.
1.14 + """
1.15 +
1.16 + return self.recurrence_is_new(recurrence) or not self.obj.is_shared()
1.17 +
1.18 + def recurrence_is_new(self, recurrence):
1.19 +
1.20 + "Return whether 'recurrence' is new to the current object."
1.21 +
1.22 + return recurrence not in self.get_stored_recurrences()
1.23
1.24 def can_remove_attendee(self, attendee):
1.25
1.26 @@ -79,6 +91,9 @@
1.27
1.28 # Access to stored object information.
1.29
1.30 + def is_organiser(self):
1.31 + return get_uri(self.obj.get_value("ORGANIZER")) == self.user
1.32 +
1.33 def get_stored_attendees(self):
1.34 return uri_values(self.obj.get_values("ATTENDEE") or [])
1.35
1.36 @@ -374,7 +389,7 @@
1.37 # Obtain the periods associated with the event.
1.38 # NOTE: Add a control to add recurrences here.
1.39
1.40 - recurrences = self.get_current_recurrences()
1.41 + recurrences = self.update_current_recurrences()
1.42
1.43 if len(recurrences) < 1:
1.44 return
1.45 @@ -459,7 +474,7 @@
1.46 page.th("")
1.47 page.td()
1.48
1.49 - remove_type = not self.obj.is_shared() or not period.origin and "submit" or "checkbox"
1.50 + remove_type = (not self.obj.is_shared() or not period.origin) and "submit" or "checkbox"
1.51 self.control("recur-remove", remove_type, str(index),
1.52 str(index) in args.get("recur-remove", []),
1.53 id="recur-remove-%d" % index, class_="remove")
1.54 @@ -887,6 +902,37 @@
1.55
1.56 return attendees
1.57
1.58 + def update_recurrences_from_page(self):
1.59 +
1.60 + "Add or remove recurrences. This does not affect the stored object."
1.61 +
1.62 + args = self.env.get_args()
1.63 +
1.64 + recurrences = self.get_recurrences_from_page()
1.65 +
1.66 + # NOTE: Addition of recurrences to be supported.
1.67 +
1.68 + # Only actually remove recurrences if the event is unsent, or if the
1.69 + # recurrence is new.
1.70 +
1.71 + if args.has_key("recur-remove"):
1.72 + still_to_remove = []
1.73 +
1.74 + for i in args["recur-remove"]:
1.75 + try:
1.76 + recurrence = recurrences[int(i)]
1.77 + except IndexError:
1.78 + continue
1.79 +
1.80 + if self.can_remove_recurrence(recurrence):
1.81 + recurrences.remove(recurrence)
1.82 + else:
1.83 + still_to_remove.append(i)
1.84 +
1.85 + args["recur-remove"] = still_to_remove
1.86 +
1.87 + return recurrences
1.88 +
1.89 # Access to current object information.
1.90
1.91 def get_current_main_period(self):
1.92 @@ -913,6 +959,15 @@
1.93 else:
1.94 return self.get_recurrences_from_page()
1.95
1.96 + def update_current_recurrences(self):
1.97 +
1.98 + "Return an updated collection of recurrences for the current object."
1.99 +
1.100 + if self.is_initial_load() or not self.is_organiser():
1.101 + return self.get_stored_recurrences()
1.102 + else:
1.103 + return self.update_recurrences_from_page()
1.104 +
1.105 def get_current_attendees(self):
1.106
1.107 """