1.1 --- a/imipweb/data.py Sun Sep 10 23:45:01 2017 +0200
1.2 +++ b/imipweb/data.py Mon Sep 11 16:39:20 2017 +0200
1.3 @@ -367,11 +367,11 @@
1.4
1.5 return all_values
1.6
1.7 -def set_date_control_values(args, name, formdates, tzid_name=None):
1.8 +def set_date_control_values(formdates, args, name, tzid_name=None):
1.9
1.10 """
1.11 - Replace form fields in 'args' starting with 'name' using the values of the
1.12 - given 'formdates'.
1.13 + Using the values of the given 'formdates', replace form fields in 'args'
1.14 + starting with 'name'.
1.15
1.16 If 'tzid_name' is specified, the time zone information will be stored in
1.17 fields starting with 'tzid_name' instead of 'name'.
1.18 @@ -396,7 +396,7 @@
1.19 replaced_name=None, tzid=None):
1.20
1.21 """
1.22 - Return period values from fields found in 'args' containing the given
1.23 + Return period values from fields found in 'args' prefixed with the given
1.24 'start_name' (for start dates), 'end_name' (for end dates),
1.25 'end_enabled_name' (to enable end dates for periods), 'times_enabled_name'
1.26 (to enable times for periods).
1.27 @@ -429,11 +429,15 @@
1.28 all_starts = get_date_control_values(args, start_name, True, tzid=tzid)
1.29 all_ends = get_date_control_values(args, end_name, True, start_name, tzid=tzid)
1.30
1.31 + # Construct period objects for each start, end, origin combination.
1.32 +
1.33 periods = []
1.34
1.35 for index, (start, end, found_origin) in \
1.36 enumerate(map(None, all_starts, all_ends, all_origins)):
1.37
1.38 + # Obtain period settings from separate controls.
1.39 +
1.40 end_enabled = str(index) in all_end_enabled
1.41 times_enabled = str(index) in all_times_enabled
1.42 replaced = str(index) in all_replaced
1.43 @@ -449,4 +453,64 @@
1.44 else:
1.45 return periods
1.46
1.47 +def set_period_control_values(periods, args, start_name, end_name,
1.48 + end_enabled_name, times_enabled_name,
1.49 + origin_name=None, replaced_name=None):
1.50 +
1.51 + """
1.52 + Using the given 'periods', replace form fields in 'args' prefixed with the
1.53 + given 'start_name' (for start dates), 'end_name' (for end dates),
1.54 + 'end_enabled_name' (to enable end dates for periods), 'times_enabled_name'
1.55 + (to enable times for periods).
1.56 +
1.57 + If 'origin_name' is specified, fields containing the name will provide
1.58 + origin information, and fields containing 'replaced_name' will indicate
1.59 + periods that are replaced.
1.60 + """
1.61 +
1.62 + # Record period settings separately.
1.63 +
1.64 + args[end_enabled_name] = []
1.65 + args[times_enabled_name] = []
1.66 +
1.67 + # Record origin and replacement information if naming is defined.
1.68 +
1.69 + if origin_name:
1.70 + args[origin_name] = []
1.71 +
1.72 + if replaced_name:
1.73 + args[replaced_name] = []
1.74 +
1.75 + all_starts = []
1.76 + all_ends = []
1.77 +
1.78 + for index, period in enumerate(periods):
1.79 +
1.80 + # Encode period settings in controls.
1.81 +
1.82 + if period.end_enabled:
1.83 + args[end_enabled_name].append(str(index))
1.84 + if period.times_enabled:
1.85 + args[times_enabled_name].append(str(index))
1.86 +
1.87 + # Add origin information where controls are present to record it.
1.88 +
1.89 + if origin_name:
1.90 + args[origin_name].append(period.origin or "")
1.91 +
1.92 + # Add replacement information where controls are present to record it.
1.93 +
1.94 + if replaced_name and period.replaced:
1.95 + args[replaced_name].append(str(index))
1.96 +
1.97 + # Collect form date information for addition below.
1.98 +
1.99 + all_starts.append(period.get_form_start())
1.100 + all_ends.append(period.get_form_end())
1.101 +
1.102 + # Set the controls for the dates.
1.103 +
1.104 + set_date_control_values(all_starts, args, start_name)
1.105 + set_date_control_values(all_ends, args, end_name, tzid_name=start_name)
1.106 +
1.107 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/imipweb/event.py Sun Sep 10 23:45:01 2017 +0200
2.2 +++ b/imipweb/event.py Mon Sep 11 16:39:20 2017 +0200
2.3 @@ -24,7 +24,8 @@
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 - get_period_control_values, PeriodError
2.8 + get_period_control_values, set_period_control_values, \
2.9 + PeriodError
2.10 from imipweb.resource import DateTimeFormUtilities, FormUtilities, ResourceClientForObject
2.11
2.12 # Fake gettext method for strings to be translated later.
2.13 @@ -1027,30 +1028,10 @@
2.14
2.15 "Set the recurrences defined in the event form."
2.16
2.17 - args = self.env.get_args()
2.18 -
2.19 - args["dtend-control-recur"] = []
2.20 - args["dttimes-control-recur"] = []
2.21 - args["recur-origin"] = []
2.22 - args["recur-replaced"] = []
2.23 -
2.24 - all_starts = []
2.25 - all_ends = []
2.26 -
2.27 - for index, period in enumerate(recurrences):
2.28 - if period.end_enabled:
2.29 - args["dtend-control-recur"].append(str(index))
2.30 - if period.times_enabled:
2.31 - args["dttimes-control-recur"].append(str(index))
2.32 - if period.replaced:
2.33 - args["recur-replaced"].append(str(index))
2.34 - args["recur-origin"].append(period.origin or "")
2.35 -
2.36 - all_starts.append(period.get_form_start())
2.37 - all_ends.append(period.get_form_end())
2.38 -
2.39 - self.set_date_control_values("dtstart-recur", all_starts)
2.40 - self.set_date_control_values("dtend-recur", all_ends, tzid_name="dtstart-recur")
2.41 + set_period_control_values(recurrences, self.env.get_args(),
2.42 + "dtstart-recur", "dtend-recur",
2.43 + "dtend-control-recur", "dttimes-control-recur",
2.44 + "recur-origin", "recur-replaced")
2.45
2.46 def get_removed_periods(self, periods):
2.47
3.1 --- a/imipweb/resource.py Sun Sep 10 23:45:01 2017 +0200
3.2 +++ b/imipweb/resource.py Mon Sep 11 16:39:20 2017 +0200
3.3 @@ -25,7 +25,6 @@
3.4 from imiptools.dates import format_datetime, to_date
3.5 from imiptools.freebusy import FreeBusyCollection
3.6 from imipweb.data import event_period_from_period, form_period_from_period, \
3.7 - get_date_control_values, set_date_control_values, \
3.8 PeriodError
3.9 from imipweb.env import CGIEnvironment
3.10 from urllib import urlencode
3.11 @@ -621,29 +620,4 @@
3.12 else:
3.13 page.td("(Unrecognised date)")
3.14
3.15 - def get_date_control_values(self, name, multiple=False, tzid_name=None):
3.16 -
3.17 - """
3.18 - Return a form date object representing fields starting with 'name'. If
3.19 - 'multiple' is set to a true value, many date objects will be returned
3.20 - corresponding to a collection of datetimes.
3.21 -
3.22 - If 'tzid_name' is specified, the time zone information will be acquired
3.23 - from fields starting with 'tzid_name' instead of 'name'.
3.24 - """
3.25 -
3.26 - get_date_control_values(self.env.get_args(), name, multiple, tzid_name, self.get_tzid())
3.27 -
3.28 - def set_date_control_values(self, name, formdates, tzid_name=None):
3.29 -
3.30 - """
3.31 - Replace form fields starting with 'name' using the values of the given
3.32 - 'formdates'.
3.33 -
3.34 - If 'tzid_name' is specified, the time zone information will be stored in
3.35 - fields starting with 'tzid_name' instead of 'name'.
3.36 - """
3.37 -
3.38 - set_date_control_values(self.env.get_args(), name, formdates, tzid_name)
3.39 -
3.40 # vim: tabstop=4 expandtab shiftwidth=4