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