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 from MoinDateSupport import getFormDate, getFormMonth, \ 12 getParameterDate, getParameterMonth 13 14 from MoinMoin.wikiutil import escape 15 16 # Utility classes and associated functions. 17 18 class ActionSupport(ActionSupport): 19 20 "Extend the generic action support." 21 22 def get_month_lists(self, default_as_current=0): 23 24 """ 25 Return two lists of HTML element definitions corresponding to the start 26 and end month selection controls, with months selected according to any 27 values that have been specified via request parameters. 28 """ 29 30 _ = self._ 31 form = self.get_form() 32 33 # Initialise month lists. 34 35 start_month_list = [] 36 end_month_list = [] 37 38 start_month = self._get_input(form, "start-month", default_as_current and getCurrentMonth().month() or None) 39 end_month = self._get_input(form, "end-month", start_month) 40 41 # Prepare month lists, selecting specified months. 42 43 if not default_as_current: 44 start_month_list.append('<option value=""></option>') 45 end_month_list.append('<option value=""></option>') 46 47 for month in range(1, 13): 48 month_label = escape(_(getMonthLabel(month))) 49 selected = self._get_selected(month, start_month) 50 start_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label)) 51 selected = self._get_selected(month, end_month) 52 end_month_list.append('<option value="%02d" %s>%s</option>' % (month, selected, month_label)) 53 54 return start_month_list, end_month_list 55 56 def get_year_defaults(self, default_as_current=0): 57 58 "Return defaults for the start and end years." 59 60 form = self.get_form() 61 62 start_year_default = form.get("start-year", [default_as_current and getCurrentYear() or ""])[0] 63 end_year_default = form.get("end-year", [default_as_current and start_year_default or ""])[0] 64 65 return start_year_default, end_year_default 66 67 def get_day_defaults(self, default_as_current=0): 68 69 "Return defaults for the start and end days." 70 71 form = self.get_form() 72 73 start_day_default = form.get("start-day", [default_as_current and getCurrentDate().day() or ""])[0] 74 end_day_default = form.get("end-day", [default_as_current and start_day_default or ""])[0] 75 76 return start_day_default, end_day_default 77 78 def get_date_functions(resolution): 79 if resolution == "date": 80 return getParameterDate, getFormDate 81 else: 82 return getParameterMonth, getFormMonth 83 84 def get_date_label_functions(resolution): 85 if resolution == "date": 86 return getParameterDate, getFullDateLabel 87 else: 88 return getParameterMonth, getFullMonthLabel 89 90 # vim: tabstop=4 expandtab shiftwidth=4