paul@347 | 1 | # -*- coding: iso-8859-1 -*- |
paul@347 | 2 | """ |
paul@347 | 3 | MoinMoin - EventAggregator action support library |
paul@347 | 4 | |
paul@347 | 5 | @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk> |
paul@347 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@347 | 7 | """ |
paul@347 | 8 | |
paul@347 | 9 | from DateSupport import * |
paul@347 | 10 | from MoinSupport import * |
paul@347 | 11 | |
paul@347 | 12 | from MoinMoin.wikiutil import escape |
paul@347 | 13 | |
paul@347 | 14 | # Utility classes and associated functions. |
paul@347 | 15 | |
paul@347 | 16 | class ActionSupport(ActionSupport): |
paul@347 | 17 | |
paul@347 | 18 | "Extend the generic action support." |
paul@347 | 19 | |
paul@347 | 20 | def get_month_lists(self, default_as_current=0): |
paul@347 | 21 | |
paul@347 | 22 | """ |
paul@347 | 23 | Return two lists of HTML element definitions corresponding to the start |
paul@347 | 24 | and end month selection controls, with months selected according to any |
paul@347 | 25 | values that have been specified via request parameters. |
paul@347 | 26 | """ |
paul@347 | 27 | |
paul@347 | 28 | _ = self._ |
paul@347 | 29 | form = self.get_form() |
paul@347 | 30 | |
paul@347 | 31 | # Initialise month lists. |
paul@347 | 32 | |
paul@347 | 33 | start_month_list = [] |
paul@347 | 34 | end_month_list = [] |
paul@347 | 35 | |
paul@347 | 36 | start_month = self._get_input(form, "start-month", default_as_current and getCurrentMonth().month() or None) |
paul@347 | 37 | end_month = self._get_input(form, "end-month", start_month) |
paul@347 | 38 | |
paul@347 | 39 | # Prepare month lists, selecting specified months. |
paul@347 | 40 | |
paul@347 | 41 | if not default_as_current: |
paul@347 | 42 | start_month_list.append('<option value=""></option>') |
paul@347 | 43 | end_month_list.append('<option value=""></option>') |
paul@347 | 44 | |
paul@347 | 45 | for month in range(1, 13): |
paul@347 | 46 | month_label = escape(_(getMonthLabel(month))) |
paul@347 | 47 | selected = self._get_selected(month, start_month) |
paul@347 | 48 | start_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label)) |
paul@347 | 49 | selected = self._get_selected(month, end_month) |
paul@347 | 50 | end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label)) |
paul@347 | 51 | |
paul@347 | 52 | return start_month_list, end_month_list |
paul@347 | 53 | |
paul@347 | 54 | def get_year_defaults(self, default_as_current=0): |
paul@347 | 55 | |
paul@347 | 56 | "Return defaults for the start and end years." |
paul@347 | 57 | |
paul@347 | 58 | form = self.get_form() |
paul@347 | 59 | |
paul@347 | 60 | start_year_default = form.get("start-year", [default_as_current and getCurrentYear() or ""])[0] |
paul@347 | 61 | end_year_default = form.get("end-year", [default_as_current and start_year_default or ""])[0] |
paul@347 | 62 | |
paul@347 | 63 | return start_year_default, end_year_default |
paul@347 | 64 | |
paul@347 | 65 | def get_day_defaults(self, default_as_current=0): |
paul@347 | 66 | |
paul@347 | 67 | "Return defaults for the start and end days." |
paul@347 | 68 | |
paul@347 | 69 | form = self.get_form() |
paul@347 | 70 | |
paul@347 | 71 | start_day_default = form.get("start-day", [default_as_current and getCurrentDate().day() or ""])[0] |
paul@347 | 72 | end_day_default = form.get("end-day", [default_as_current and start_day_default or ""])[0] |
paul@347 | 73 | |
paul@347 | 74 | return start_day_default, end_day_default |
paul@347 | 75 | |
paul@347 | 76 | # vim: tabstop=4 expandtab shiftwidth=4 |