1.1 --- a/EventAggregatorSupport.py Thu Jul 08 02:17:12 2010 +0200
1.2 +++ b/EventAggregatorSupport.py Thu Jul 08 22:15:54 2010 +0200
1.3 @@ -121,11 +121,87 @@
1.4
1.5 class ActionSupport:
1.6
1.7 - "Work around disruptive MoinMoin changes in 1.9."
1.8 + """
1.9 + Work around disruptive MoinMoin changes in 1.9, and also provide useful
1.10 + convenience methods.
1.11 + """
1.12
1.13 def get_form(self):
1.14 return get_form(self.request)
1.15
1.16 + def _get_selected(self, value, input_value):
1.17 +
1.18 + """
1.19 + Return the HTML attribute text indicating selection of an option (or
1.20 + otherwise) if 'value' matches 'input_value'.
1.21 + """
1.22 +
1.23 + return input_value is not None and value == input_value and 'selected="selected"' or ''
1.24 +
1.25 + def _get_selected_for_list(self, value, input_values):
1.26 +
1.27 + """
1.28 + Return the HTML attribute text indicating selection of an option (or
1.29 + otherwise) if 'value' matches one of the 'input_values'.
1.30 + """
1.31 +
1.32 + return value in input_values and 'selected="selected"' or ''
1.33 +
1.34 + def _get_input(self, form, name, default=None):
1.35 +
1.36 + """
1.37 + Return the input from 'form' having the given 'name', returning either
1.38 + the input converted to an integer or the given 'default' (optional, None
1.39 + if not specified).
1.40 + """
1.41 +
1.42 + value = form.get(name, [None])[0]
1.43 + if not value: # true if 0 obtained
1.44 + return default
1.45 + else:
1.46 + return int(value)
1.47 +
1.48 + def get_month_lists(self):
1.49 +
1.50 + """
1.51 + Return two lists of HTML element definitions corresponding to the start
1.52 + and end month selection controls, with months selected according to any
1.53 + values that have been specified via request parameters.
1.54 + """
1.55 +
1.56 + _ = self._
1.57 + form = self.get_form()
1.58 +
1.59 + # Initialise month lists.
1.60 +
1.61 + start_month_list = []
1.62 + end_month_list = []
1.63 +
1.64 + start_month = self._get_input(form, "start-month", getCurrentMonth().month())
1.65 + end_month = self._get_input(form, "end-month", start_month)
1.66 +
1.67 + # Prepare month lists, selecting specified months.
1.68 +
1.69 + for month in range(1, 13):
1.70 + month_label = _(getMonthLabel(month))
1.71 + selected = self._get_selected(month, start_month)
1.72 + start_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label))
1.73 + selected = self._get_selected(month, end_month)
1.74 + end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label))
1.75 +
1.76 + return start_month_list, end_month_list
1.77 +
1.78 + def get_year_defaults(self):
1.79 +
1.80 + "Return defaults for the start and end years."
1.81 +
1.82 + form = self.get_form()
1.83 +
1.84 + start_year_default = form.get("start-year", [""])[0] or getCurrentYear()
1.85 + end_year_default = form.get("end-year", [""])[0] or start_year_default
1.86 +
1.87 + return start_year_default, end_year_default
1.88 +
1.89 def get_form(request):
1.90
1.91 "Work around disruptive MoinMoin changes in 1.9."