1.1 --- a/imipweb/event.py Tue Sep 12 22:09:24 2017 +0200
1.2 +++ b/imipweb/event.py Tue Sep 12 23:07:14 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, \
1.10 PeriodError
1.11 from imipweb.resource import DateTimeFormUtilities, FormUtilities, ResourceClientForObject
1.12 @@ -1004,19 +1006,6 @@
1.13 periods.append(p.as_event_period(i))
1.14 return periods
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 @@ -1065,50 +1054,6 @@
1.33 attendee_map = self.obj.get_value_map("ATTENDEE")
1.34 return [get_verbose_address(value, attendee_map.get(value)) for value in attendees]
1.35
1.36 - def filter_duplicates(self, l):
1.37 -
1.38 - """
1.39 - Return collection 'l' filtered for duplicate values, retaining the given
1.40 - element ordering.
1.41 - """
1.42 -
1.43 - s = set()
1.44 - f = []
1.45 -
1.46 - for value in l:
1.47 - if value not in s:
1.48 - s.add(value)
1.49 - f.append(value)
1.50 -
1.51 - return f
1.52 -
1.53 - def remove_from_collection(self, l, indexes, fn):
1.54 -
1.55 - """
1.56 - Remove from collection 'l' all values having 'indexes' where 'fn'
1.57 - applied to each referenced value returns a true value. Values where 'fn'
1.58 - returns a false value are added to a list of deferred removals which is
1.59 - returned.
1.60 - """
1.61 -
1.62 - still_to_remove = []
1.63 - correction = 0
1.64 -
1.65 - for i in indexes:
1.66 - try:
1.67 - i = int(i) - correction
1.68 - value = l[i]
1.69 - except (IndexError, ValueError):
1.70 - continue
1.71 -
1.72 - if fn(value):
1.73 - del l[i]
1.74 - correction += 1
1.75 - else:
1.76 - still_to_remove.append(value)
1.77 -
1.78 - return still_to_remove
1.79 -
1.80 def update_attendees_from_page(self):
1.81
1.82 "Add or remove attendees. This does not affect the stored object."
1.83 @@ -1141,12 +1086,12 @@
1.84 remove = args.has_key("remove")
1.85
1.86 if remove:
1.87 - still_to_remove = self.remove_from_collection(attendees,
1.88 + still_to_remove = remove_from_collection(attendees,
1.89 args["remove"], self.can_remove_attendee)
1.90 self.set_state("remove", still_to_remove)
1.91
1.92 if add or add_suggested or remove:
1.93 - attendees = self.filter_duplicates(attendees)
1.94 + attendees = filter_duplicates(attendees)
1.95
1.96 return attendees
1.97
1.98 @@ -1171,12 +1116,12 @@
1.99 remove = args.has_key("recur-remove")
1.100
1.101 if remove:
1.102 - still_to_remove = self.remove_from_collection(recurrences,
1.103 + still_to_remove = remove_from_collection(recurrences,
1.104 args["recur-remove"], self.can_remove_recurrence)
1.105 self.set_state("recur-remove", still_to_remove)
1.106
1.107 if add or remove:
1.108 - recurrences = self.filter_duplicates(recurrences)
1.109 + recurrences = filter_duplicates(recurrences)
1.110
1.111 return recurrences
1.112
1.113 @@ -1273,7 +1218,7 @@
1.114
1.115 # Get all periods that are not replaced.
1.116
1.117 - active_periods = self.get_active_periods(periods)
1.118 + active_periods = get_active_periods(periods)
1.119
1.120 for period in self.get_state("recur-remove", list):
1.121 active_periods[period] -= 1