# HG changeset patch # User Paul Boddie # Date 1443475374 -7200 # Node ID 9cf10fe21c3ae6dc6d65fc75c53b3bde2bc6b7b6 # Parent 3737f863dd7b3beeb96497cb5fc6f776c4782d97 Separated attendee/recurrence manipulation from presentation, introducing form field dictionary updates from form period/date objects, also simplifying the processing of attendees, removing filtering operations during editing. diff -r 3737f863dd7b -r 9cf10fe21c3a imipweb/event.py --- a/imipweb/event.py Mon Sep 28 23:12:58 2015 +0200 +++ b/imipweb/event.py Mon Sep 28 23:22:54 2015 +0200 @@ -191,7 +191,7 @@ # Obtain basic event information, generating any necessary editing controls. - attendees = self.update_current_attendees() + attendees = self.get_current_attendees() period = self.get_current_main_period() self.show_object_datetime_controls(period) @@ -409,7 +409,7 @@ # Obtain the periods associated with the event. # NOTE: Add a control to add recurrences here. - recurrences = self.update_current_recurrences() + recurrences = self.get_current_recurrences() if len(recurrences) < 1: return @@ -590,8 +590,10 @@ for participant in self.get_current_attendees(): if participant == self.user: freebusy = self.store.get_freebusy(participant) + elif participant: + freebusy = self.store.get_freebusy_for_other(self.user, participant) else: - freebusy = self.store.get_freebusy_for_other(self.user, participant) + continue if not freebusy: continue @@ -866,6 +868,32 @@ return periods + def set_recurrences_in_page(self, recurrences): + + "Set the recurrences defined in the event form." + + args = self.env.get_args() + + args["dtend-control-recur"] = [] + args["dttimes-control-recur"] = [] + args["recur-origin"] = [] + + all_starts = [] + all_ends = [] + + for index, period in enumerate(recurrences): + if period.end_enabled: + args["dtend-control-recur"].append(str(index)) + if period.times_enabled: + args["dttimes-control-recur"].append(str(index)) + args["recur-origin"].append(period.origin or "") + + all_starts.append(period.get_form_start()) + all_ends.append(period.get_form_end()) + + self.set_date_control_values("dtstart-recur", all_starts) + self.set_date_control_values("dtend-recur", all_ends, tzid_name="dtstart-recur") + def get_removed_periods(self, periods): """ @@ -894,25 +922,18 @@ def get_attendees_from_page(self): """ - Return attendees from the request, normalised for iCalendar purposes, - and without duplicates. + Return attendees from the request, normalised for iCalendar purposes. """ args = self.env.get_args() - - attendees = args.get("attendee", []) - unique_attendees = set() - ordered_attendees = [] + attendees = [] - for attendee in attendees: - if not attendee.strip(): - continue - attendee = get_uri(attendee) - if attendee not in unique_attendees: - unique_attendees.add(attendee) - ordered_attendees.append(attendee) + for attendee in args.get("attendee", []): + if attendee.strip(): + attendee = get_uri(attendee) + attendees.append(attendee) - return ordered_attendees + return attendees def update_attendees_from_page(self): @@ -944,6 +965,7 @@ args["remove"] = still_to_remove + args["attendee"] = attendees return attendees def update_recurrences_from_page(self): @@ -975,6 +997,7 @@ args["recur-remove"] = still_to_remove + self.set_recurrences_in_page(recurrences) return recurrences # Access to current object information. @@ -1052,6 +1075,9 @@ if not errors: return True + self.update_current_attendees() + self.update_current_recurrences() + self.new_page(title="Event") self.show_object_on_page(errors) diff -r 3737f863dd7b -r 9cf10fe21c3a imipweb/resource.py --- a/imipweb/resource.py Mon Sep 28 23:12:58 2015 +0200 +++ b/imipweb/resource.py Mon Sep 28 23:22:54 2015 +0200 @@ -548,11 +548,12 @@ def get_date_control_values(self, name, multiple=False, tzid_name=None): """ - Return a dictionary containing date, time and tzid entries for fields - starting with 'name'. If 'multiple' is set to a true value, many - dictionaries will be returned corresponding to a collection of - datetimes. If 'tzid_name' is specified, the time zone information will - be acquired from a field starting with 'tzid_name' instead of 'name'. + Return a form date object representing fields starting with 'name'. If + 'multiple' is set to a true value, many date objects will be returned + corresponding to a collection of datetimes. + + If 'tzid_name' is specified, the time zone information will be acquired + from fields starting with 'tzid_name' instead of 'name'. """ args = self.env.get_args() @@ -583,4 +584,22 @@ return all_values + def set_date_control_values(self, name, formdates, tzid_name=None): + + """ + Replace form fields starting with 'name' using the values of the given + 'formdates'. + + If 'tzid_name' is specified, the time zone information will be stored in + fields starting with 'tzid_name' instead of 'name'. + """ + + args = self.env.get_args() + + args["%s-date" % name] = [d.date for d in formdates] + args["%s-hour" % name] = [d.hour for d in formdates] + args["%s-minute" % name] = [d.minute for d in formdates] + args["%s-second" % name] = [d.second for d in formdates] + args["%s-tzid" % (tzid_name or name)] = [d.tzid for d in formdates] + # vim: tabstop=4 expandtab shiftwidth=4