# HG changeset patch # User Paul Boddie # Date 1505423910 -7200 # Node ID e3cda8fa8ee7e22afbc0b775db3b4ee9ae0ddbab # Parent 99f3406e26ee59c0095bce4d962346a627118c7d Introduced recurrence identifiers for periods originating from stored data, thus permitting the tracking of these periods and the operations they experience during editing. diff -r 99f3406e26ee -r e3cda8fa8ee7 imipweb/data.py --- a/imipweb/data.py Thu Sep 14 23:15:48 2017 +0200 +++ b/imipweb/data.py Thu Sep 14 23:18:30 2017 +0200 @@ -86,7 +86,8 @@ isinstance(self.start, datetime) or isinstance(self.end, datetime), self.tzid, self.origin, - self.replaced and True or False + self.replaced and True or False, + format_datetime(self.get_start_point()) ) def get_form_date(self, dt, attr=None): @@ -104,7 +105,7 @@ "A period whose information originates from a form." def __init__(self, start, end, end_enabled=True, times_enabled=True, - tzid=None, origin=None, replaced=False): + tzid=None, origin=None, replaced=False, recurrenceid=None): self.start = start self.end = end self.end_enabled = end_enabled @@ -112,19 +113,16 @@ self.tzid = tzid self.origin = origin self.replaced = replaced + self.recurrenceid = recurrenceid def as_tuple(self): - return self.start, self.end, self.end_enabled, self.times_enabled, self.tzid, self.origin, self.replaced + return self.start, self.end, self.end_enabled, self.times_enabled, self.tzid, self.origin, self.replaced, self.recurrenceid def __repr__(self): return "FormPeriod%r" % (self.as_tuple(),) - def __cmp__(self, other): - result = RecurringPeriod.__cmp__(self, other) - if result: - return result - other = form_period_from_period(other) - return cmp(self.replaced, other.replaced) + def is_changed(self): + return not self.recurrenceid or format_datetime(self.get_start_point()) != self.recurrenceid def as_event_period(self, index=None): @@ -470,7 +468,8 @@ def get_period_control_values(args, start_name, end_name, end_enabled_name, times_enabled_name, origin=None, origin_name=None, - replaced_name=None, tzid=None): + replaced_name=None, recurrenceid_name=None, + tzid=None): """ Return period values from fields found in 'args' prefixed with the given @@ -480,8 +479,9 @@ If 'origin' is specified, a single period with the given origin is returned. If 'origin_name' is specified, fields containing the name will - provide origin information, and fields containing 'replaced_name' will - indicate periods that are replaced. + provide origin information, fields containing 'replaced_name' will indicate + periods that are replaced, and fields containing 'recurrenceid_name' will + indicate periods that have existing recurrence details from an event. If 'tzid' is specified, it will provide the time zone where no explicit time zone information is indicated in the field data. @@ -500,6 +500,7 @@ all_origins = origin_name and args.get(origin_name, []) or [] all_replaced = replaced_name and args.get(replaced_name, []) or [] + all_recurrenceids = recurrenceid_name and args.get(recurrenceid_name, []) or [] # Get the start and end datetimes. @@ -510,8 +511,8 @@ periods = [] - for index, (start, end, found_origin) in \ - enumerate(map(None, all_starts, all_ends, all_origins)): + for index, (start, end, found_origin, recurrenceid) in \ + enumerate(map(None, all_starts, all_ends, all_origins, all_recurrenceids)): # Obtain period settings from separate controls. @@ -520,7 +521,7 @@ replaced = str(index) in all_replaced period = FormPeriod(start, end, end_enabled, times_enabled, tzid, - found_origin or origin, replaced) + found_origin or origin, replaced, recurrenceid) periods.append(period) # Return a single period if a single origin was specified. @@ -532,7 +533,8 @@ def set_period_control_values(periods, args, start_name, end_name, end_enabled_name, times_enabled_name, - origin_name=None, replaced_name=None): + origin_name=None, replaced_name=None, + recurrenceid_name=None): """ Using the given 'periods', replace form fields in 'args' prefixed with the @@ -541,8 +543,9 @@ (to enable times for periods). If 'origin_name' is specified, fields containing the name will provide - origin information, and fields containing 'replaced_name' will indicate - periods that are replaced. + origin information, fields containing 'replaced_name' will indicate periods + that are replaced, and fields containing 'recurrenceid_name' will indicate + periods that have existing recurrence details from an event. """ # Record period settings separately. @@ -558,6 +561,9 @@ if replaced_name: args[replaced_name] = [] + if recurrenceid_name: + args[recurrenceid_name] = [] + all_starts = [] all_ends = [] @@ -580,6 +586,11 @@ if replaced_name and period.replaced: args[replaced_name].append(str(index)) + # Add recurrence identifiers where controls are present to record it. + + if recurrenceid_name: + args[recurrenceid_name].append(period.recurrenceid or "") + # Collect form date information for addition below. all_starts.append(period.get_form_start()) diff -r 99f3406e26ee -r e3cda8fa8ee7 imipweb/event.py --- a/imipweb/event.py Thu Sep 14 23:15:48 2017 +0200 +++ b/imipweb/event.py Thu Sep 14 23:18:30 2017 +0200 @@ -24,6 +24,7 @@ from imiptools.dates import format_datetime, to_timezone from imiptools.mail import Messenger from imipweb.data import EventPeriod, event_period_from_period, \ + form_period_from_period, \ filter_duplicates, get_active_periods, \ get_removed_periods, remove_from_collection, \ get_period_control_values, \ @@ -81,7 +82,7 @@ "Return whether 'recurrence' is new to the current object." - return recurrence not in self.get_stored_recurrences() + return not form_period_from_period(recurrence).recurrenceid def can_remove_attendee(self, attendee): @@ -1033,6 +1034,7 @@ "dtstart-recur", "dtend-recur", "dtend-control-recur", "dttimes-control-recur", origin_name="recur-origin", replaced_name="recur-replaced", + recurrenceid_name="recur-id", tzid=self.get_tzid()) def get_removed_periods(self, periods): diff -r 99f3406e26ee -r e3cda8fa8ee7 imipweb/resource.py --- a/imipweb/resource.py Thu Sep 14 23:15:48 2017 +0200 +++ b/imipweb/resource.py Thu Sep 14 23:18:30 2017 +0200 @@ -556,11 +556,7 @@ page.label("Specify dates only", for_=_id("dttimes-enable", index), class_="time enabled disable") page.div.close() - # Put the origin somewhere. - - self.control("recur-origin", "hidden", period.origin or "") - self.control("recur-replaced", "hidden", period.replaced and str(index) or "") - + self.show_recurrence_state(index, period) else: self.date_controls(_name("dtend", "recur", index), period.get_form_end(), show_tzid=False, read_only=read_only) if not read_only: @@ -612,12 +608,19 @@ page.td(class_=css) if show_start: self.date_controls(_name("dtstart", "recur", index), period.get_form_start(), read_only=True) - self.control("recur-origin", "hidden", period.origin or "") - self.control("recur-replaced", "hidden", period.replaced and str(index) or "") + self.show_recurrence_state(index, period) else: self.date_controls(_name("dtend", "recur", index), period.get_form_end(), show_tzid=False, read_only=True) page.td.close() else: page.td("(Unrecognised date)") + def show_recurrence_state(self, index, period): + + "Insert at 'index' additional state held by 'period'." + + self.control("recur-origin", "hidden", period.origin or "") + self.control("recur-replaced", "hidden", period.replaced and str(index) or "") + self.control("recur-id", "hidden", period.recurrenceid or "") + # vim: tabstop=4 expandtab shiftwidth=4