1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/EventAggregatorSupport/Actions.py Tue Apr 30 23:49:32 2013 +0200
1.3 @@ -0,0 +1,76 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - EventAggregator action support library
1.7 +
1.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +from DateSupport import *
1.13 +from MoinSupport import *
1.14 +
1.15 +from MoinMoin.wikiutil import escape
1.16 +
1.17 +# Utility classes and associated functions.
1.18 +
1.19 +class ActionSupport(ActionSupport):
1.20 +
1.21 + "Extend the generic action support."
1.22 +
1.23 + def get_month_lists(self, default_as_current=0):
1.24 +
1.25 + """
1.26 + Return two lists of HTML element definitions corresponding to the start
1.27 + and end month selection controls, with months selected according to any
1.28 + values that have been specified via request parameters.
1.29 + """
1.30 +
1.31 + _ = self._
1.32 + form = self.get_form()
1.33 +
1.34 + # Initialise month lists.
1.35 +
1.36 + start_month_list = []
1.37 + end_month_list = []
1.38 +
1.39 + start_month = self._get_input(form, "start-month", default_as_current and getCurrentMonth().month() or None)
1.40 + end_month = self._get_input(form, "end-month", start_month)
1.41 +
1.42 + # Prepare month lists, selecting specified months.
1.43 +
1.44 + if not default_as_current:
1.45 + start_month_list.append('<option value=""></option>')
1.46 + end_month_list.append('<option value=""></option>')
1.47 +
1.48 + for month in range(1, 13):
1.49 + month_label = escape(_(getMonthLabel(month)))
1.50 + selected = self._get_selected(month, start_month)
1.51 + start_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label))
1.52 + selected = self._get_selected(month, end_month)
1.53 + end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label))
1.54 +
1.55 + return start_month_list, end_month_list
1.56 +
1.57 + def get_year_defaults(self, default_as_current=0):
1.58 +
1.59 + "Return defaults for the start and end years."
1.60 +
1.61 + form = self.get_form()
1.62 +
1.63 + start_year_default = form.get("start-year", [default_as_current and getCurrentYear() or ""])[0]
1.64 + end_year_default = form.get("end-year", [default_as_current and start_year_default or ""])[0]
1.65 +
1.66 + return start_year_default, end_year_default
1.67 +
1.68 + def get_day_defaults(self, default_as_current=0):
1.69 +
1.70 + "Return defaults for the start and end days."
1.71 +
1.72 + form = self.get_form()
1.73 +
1.74 + start_day_default = form.get("start-day", [default_as_current and getCurrentDate().day() or ""])[0]
1.75 + end_day_default = form.get("end-day", [default_as_current and start_day_default or ""])[0]
1.76 +
1.77 + return start_day_default, end_day_default
1.78 +
1.79 +# vim: tabstop=4 expandtab shiftwidth=4