1.1 --- a/imipweb/event.py Tue Sep 12 21:58:33 2017 +0200
1.2 +++ b/imipweb/event.py Tue Sep 12 23:02:29 2017 +0200
1.3 @@ -24,6 +24,8 @@
1.4 from imiptools.dates import format_datetime, to_timezone
1.5 from imiptools.mail import Messenger
1.6 from imipweb.data import EventPeriod, event_period_from_period, \
1.7 + filter_duplicates, get_active_periods, \
1.8 + remove_from_collection, \
1.9 get_period_control_values, set_period_control_values, \
1.10 PeriodError
1.11 from imipweb.resource import DateTimeFormUtilities, FormUtilities, ResourceClientForObject
1.12 @@ -996,19 +998,6 @@
1.13
1.14 return [p.as_event_period(i) for i, p in enumerate(self.get_recurrences_from_page())]
1.15
1.16 - def get_active_periods(self, periods):
1.17 -
1.18 - "Return a mapping of non-replaced periods to counts, given 'periods'."
1.19 -
1.20 - active_periods = {}
1.21 - for p in periods:
1.22 - if not p.replaced:
1.23 - if not active_periods.has_key(p):
1.24 - active_periods[p] = 1
1.25 - else:
1.26 - active_periods[p] += 1
1.27 - return active_periods
1.28 -
1.29 # Access to form-originating object information.
1.30
1.31 def get_main_period_from_page(self):
1.32 @@ -1061,7 +1050,7 @@
1.33
1.34 # Get all periods that are not replaced.
1.35
1.36 - active_periods = self.get_active_periods(periods)
1.37 + active_periods = get_active_periods(periods)
1.38
1.39 for i in args.get("recur-remove", []):
1.40 try:
1.41 @@ -1109,50 +1098,6 @@
1.42 attendee_map = self.obj.get_value_map("ATTENDEE")
1.43 return [get_verbose_address(value, attendee_map.get(value)) for value in attendees]
1.44
1.45 - def filter_duplicates(self, l):
1.46 -
1.47 - """
1.48 - Return collection 'l' filtered for duplicate values, retaining the given
1.49 - element ordering.
1.50 - """
1.51 -
1.52 - s = set()
1.53 - f = []
1.54 -
1.55 - for value in l:
1.56 - if value not in s:
1.57 - s.add(value)
1.58 - f.append(value)
1.59 -
1.60 - return f
1.61 -
1.62 - def remove_from_collection(self, l, indexes, fn):
1.63 -
1.64 - """
1.65 - Remove from collection 'l' all values having 'indexes' where 'fn'
1.66 - applied to each referenced value returns a true value. Values where 'fn'
1.67 - returns a false value are added to a list of deferred removals which is
1.68 - returned.
1.69 - """
1.70 -
1.71 - still_to_remove = []
1.72 - correction = 0
1.73 -
1.74 - for i in indexes:
1.75 - try:
1.76 - i = int(i) - correction
1.77 - value = l[i]
1.78 - except (IndexError, ValueError):
1.79 - continue
1.80 -
1.81 - if fn(value):
1.82 - del l[i]
1.83 - correction += 1
1.84 - else:
1.85 - still_to_remove.append(str(i))
1.86 -
1.87 - return still_to_remove
1.88 -
1.89 def update_attendees_from_page(self):
1.90
1.91 "Add or remove attendees. This does not affect the stored object."
1.92 @@ -1185,12 +1130,12 @@
1.93 remove = args.has_key("remove")
1.94
1.95 if remove:
1.96 - still_to_remove = self.remove_from_collection(attendees,
1.97 + still_to_remove = remove_from_collection(attendees,
1.98 args["remove"], self.can_remove_attendee)
1.99 args["remove"] = still_to_remove
1.100
1.101 if add or add_suggested or remove:
1.102 - attendees = self.filter_duplicates(attendees)
1.103 + attendees = filter_duplicates(attendees)
1.104
1.105 args["attendee"] = attendees
1.106 return attendees
1.107 @@ -1216,12 +1161,12 @@
1.108 remove = args.has_key("recur-remove")
1.109
1.110 if remove:
1.111 - still_to_remove = self.remove_from_collection(recurrences,
1.112 + still_to_remove = remove_from_collection(recurrences,
1.113 args["recur-remove"], self.can_remove_recurrence)
1.114 args["recur-remove"] = still_to_remove
1.115
1.116 if add or remove:
1.117 - recurrences = self.filter_duplicates(recurrences)
1.118 + recurrences = filter_duplicates(recurrences)
1.119
1.120 self.set_recurrences_in_page(recurrences)
1.121 return recurrences