1.1 --- a/imipweb/data.py Thu Sep 14 23:15:48 2017 +0200
1.2 +++ b/imipweb/data.py Thu Sep 14 23:18:30 2017 +0200
1.3 @@ -86,7 +86,8 @@
1.4 isinstance(self.start, datetime) or isinstance(self.end, datetime),
1.5 self.tzid,
1.6 self.origin,
1.7 - self.replaced and True or False
1.8 + self.replaced and True or False,
1.9 + format_datetime(self.get_start_point())
1.10 )
1.11
1.12 def get_form_date(self, dt, attr=None):
1.13 @@ -104,7 +105,7 @@
1.14 "A period whose information originates from a form."
1.15
1.16 def __init__(self, start, end, end_enabled=True, times_enabled=True,
1.17 - tzid=None, origin=None, replaced=False):
1.18 + tzid=None, origin=None, replaced=False, recurrenceid=None):
1.19 self.start = start
1.20 self.end = end
1.21 self.end_enabled = end_enabled
1.22 @@ -112,19 +113,16 @@
1.23 self.tzid = tzid
1.24 self.origin = origin
1.25 self.replaced = replaced
1.26 + self.recurrenceid = recurrenceid
1.27
1.28 def as_tuple(self):
1.29 - return self.start, self.end, self.end_enabled, self.times_enabled, self.tzid, self.origin, self.replaced
1.30 + return self.start, self.end, self.end_enabled, self.times_enabled, self.tzid, self.origin, self.replaced, self.recurrenceid
1.31
1.32 def __repr__(self):
1.33 return "FormPeriod%r" % (self.as_tuple(),)
1.34
1.35 - def __cmp__(self, other):
1.36 - result = RecurringPeriod.__cmp__(self, other)
1.37 - if result:
1.38 - return result
1.39 - other = form_period_from_period(other)
1.40 - return cmp(self.replaced, other.replaced)
1.41 + def is_changed(self):
1.42 + return not self.recurrenceid or format_datetime(self.get_start_point()) != self.recurrenceid
1.43
1.44 def as_event_period(self, index=None):
1.45
1.46 @@ -470,7 +468,8 @@
1.47 def get_period_control_values(args, start_name, end_name,
1.48 end_enabled_name, times_enabled_name,
1.49 origin=None, origin_name=None,
1.50 - replaced_name=None, tzid=None):
1.51 + replaced_name=None, recurrenceid_name=None,
1.52 + tzid=None):
1.53
1.54 """
1.55 Return period values from fields found in 'args' prefixed with the given
1.56 @@ -480,8 +479,9 @@
1.57
1.58 If 'origin' is specified, a single period with the given origin is
1.59 returned. If 'origin_name' is specified, fields containing the name will
1.60 - provide origin information, and fields containing 'replaced_name' will
1.61 - indicate periods that are replaced.
1.62 + provide origin information, fields containing 'replaced_name' will indicate
1.63 + periods that are replaced, and fields containing 'recurrenceid_name' will
1.64 + indicate periods that have existing recurrence details from an event.
1.65
1.66 If 'tzid' is specified, it will provide the time zone where no explicit
1.67 time zone information is indicated in the field data.
1.68 @@ -500,6 +500,7 @@
1.69 all_origins = origin_name and args.get(origin_name, []) or []
1.70
1.71 all_replaced = replaced_name and args.get(replaced_name, []) or []
1.72 + all_recurrenceids = recurrenceid_name and args.get(recurrenceid_name, []) or []
1.73
1.74 # Get the start and end datetimes.
1.75
1.76 @@ -510,8 +511,8 @@
1.77
1.78 periods = []
1.79
1.80 - for index, (start, end, found_origin) in \
1.81 - enumerate(map(None, all_starts, all_ends, all_origins)):
1.82 + for index, (start, end, found_origin, recurrenceid) in \
1.83 + enumerate(map(None, all_starts, all_ends, all_origins, all_recurrenceids)):
1.84
1.85 # Obtain period settings from separate controls.
1.86
1.87 @@ -520,7 +521,7 @@
1.88 replaced = str(index) in all_replaced
1.89
1.90 period = FormPeriod(start, end, end_enabled, times_enabled, tzid,
1.91 - found_origin or origin, replaced)
1.92 + found_origin or origin, replaced, recurrenceid)
1.93 periods.append(period)
1.94
1.95 # Return a single period if a single origin was specified.
1.96 @@ -532,7 +533,8 @@
1.97
1.98 def set_period_control_values(periods, args, start_name, end_name,
1.99 end_enabled_name, times_enabled_name,
1.100 - origin_name=None, replaced_name=None):
1.101 + origin_name=None, replaced_name=None,
1.102 + recurrenceid_name=None):
1.103
1.104 """
1.105 Using the given 'periods', replace form fields in 'args' prefixed with the
1.106 @@ -541,8 +543,9 @@
1.107 (to enable times for periods).
1.108
1.109 If 'origin_name' is specified, fields containing the name will provide
1.110 - origin information, and fields containing 'replaced_name' will indicate
1.111 - periods that are replaced.
1.112 + origin information, fields containing 'replaced_name' will indicate periods
1.113 + that are replaced, and fields containing 'recurrenceid_name' will indicate
1.114 + periods that have existing recurrence details from an event.
1.115 """
1.116
1.117 # Record period settings separately.
1.118 @@ -558,6 +561,9 @@
1.119 if replaced_name:
1.120 args[replaced_name] = []
1.121
1.122 + if recurrenceid_name:
1.123 + args[recurrenceid_name] = []
1.124 +
1.125 all_starts = []
1.126 all_ends = []
1.127
1.128 @@ -580,6 +586,11 @@
1.129 if replaced_name and period.replaced:
1.130 args[replaced_name].append(str(index))
1.131
1.132 + # Add recurrence identifiers where controls are present to record it.
1.133 +
1.134 + if recurrenceid_name:
1.135 + args[recurrenceid_name].append(period.recurrenceid or "")
1.136 +
1.137 # Collect form date information for addition below.
1.138
1.139 all_starts.append(period.get_form_start())
2.1 --- a/imipweb/event.py Thu Sep 14 23:15:48 2017 +0200
2.2 +++ b/imipweb/event.py Thu Sep 14 23:18:30 2017 +0200
2.3 @@ -24,6 +24,7 @@
2.4 from imiptools.dates import format_datetime, to_timezone
2.5 from imiptools.mail import Messenger
2.6 from imipweb.data import EventPeriod, event_period_from_period, \
2.7 + form_period_from_period, \
2.8 filter_duplicates, get_active_periods, \
2.9 get_removed_periods, remove_from_collection, \
2.10 get_period_control_values, \
2.11 @@ -81,7 +82,7 @@
2.12
2.13 "Return whether 'recurrence' is new to the current object."
2.14
2.15 - return recurrence not in self.get_stored_recurrences()
2.16 + return not form_period_from_period(recurrence).recurrenceid
2.17
2.18 def can_remove_attendee(self, attendee):
2.19
2.20 @@ -1033,6 +1034,7 @@
2.21 "dtstart-recur", "dtend-recur",
2.22 "dtend-control-recur", "dttimes-control-recur",
2.23 origin_name="recur-origin", replaced_name="recur-replaced",
2.24 + recurrenceid_name="recur-id",
2.25 tzid=self.get_tzid())
2.26
2.27 def get_removed_periods(self, periods):
3.1 --- a/imipweb/resource.py Thu Sep 14 23:15:48 2017 +0200
3.2 +++ b/imipweb/resource.py Thu Sep 14 23:18:30 2017 +0200
3.3 @@ -556,11 +556,7 @@
3.4 page.label("Specify dates only", for_=_id("dttimes-enable", index), class_="time enabled disable")
3.5 page.div.close()
3.6
3.7 - # Put the origin somewhere.
3.8 -
3.9 - self.control("recur-origin", "hidden", period.origin or "")
3.10 - self.control("recur-replaced", "hidden", period.replaced and str(index) or "")
3.11 -
3.12 + self.show_recurrence_state(index, period)
3.13 else:
3.14 self.date_controls(_name("dtend", "recur", index), period.get_form_end(), show_tzid=False, read_only=read_only)
3.15 if not read_only:
3.16 @@ -612,12 +608,19 @@
3.17 page.td(class_=css)
3.18 if show_start:
3.19 self.date_controls(_name("dtstart", "recur", index), period.get_form_start(), read_only=True)
3.20 - self.control("recur-origin", "hidden", period.origin or "")
3.21 - self.control("recur-replaced", "hidden", period.replaced and str(index) or "")
3.22 + self.show_recurrence_state(index, period)
3.23 else:
3.24 self.date_controls(_name("dtend", "recur", index), period.get_form_end(), show_tzid=False, read_only=True)
3.25 page.td.close()
3.26 else:
3.27 page.td("(Unrecognised date)")
3.28
3.29 + def show_recurrence_state(self, index, period):
3.30 +
3.31 + "Insert at 'index' additional state held by 'period'."
3.32 +
3.33 + self.control("recur-origin", "hidden", period.origin or "")
3.34 + self.control("recur-replaced", "hidden", period.replaced and str(index) or "")
3.35 + self.control("recur-id", "hidden", period.recurrenceid or "")
3.36 +
3.37 # vim: tabstop=4 expandtab shiftwidth=4