equal
deleted
inserted
replaced
1 """ |
1 """ |
2 Some additional helpers |
2 Some additional helpers |
3 """ |
3 """ |
4 |
4 |
5 import datetime, calendar |
5 import datetime |
|
6 import calendar as _calendar |
6 |
7 |
7 import qmsk.web.helpers |
8 import qmsk.web.helpers |
8 |
9 |
9 import preferences, urls, config |
10 import preferences, urls, config |
10 |
11 |
15 |
16 |
16 # set contructor... |
17 # set contructor... |
17 set = set |
18 set = set |
18 |
19 |
19 # reference to calendar instance |
20 # reference to calendar instance |
20 calendar = calendar.Calendar() |
21 calendar = _calendar.Calendar() |
|
22 |
|
23 # list of (month_num, month_name) for the months in the year |
|
24 months = list(enumerate(_calendar.month_name))[1:] |
21 |
25 |
22 def tz_name (self, tz) : |
26 def tz_name (self, tz) : |
23 """ |
27 """ |
24 Returns a string describing the given timezone |
28 Returns a string describing the given timezone |
25 """ |
29 """ |
36 def fmt_weekday (self, wday) : |
40 def fmt_weekday (self, wday) : |
37 """ |
41 """ |
38 Formats an abbreviated weekday name |
42 Formats an abbreviated weekday name |
39 """ |
43 """ |
40 |
44 |
41 return calendar.day_abbr[wday] |
45 return _calendar.day_abbr[wday] |
42 |
46 |
43 def build_date (self, month, mday) : |
47 def build_date (self, month, mday) : |
44 """ |
48 """ |
45 Returns a datetime.date for the given (month.year, month.month, mday) |
49 Returns a datetime.date for the given (month.year, month.month, mday) |
46 """ |
50 """ |
196 Returns the largest of the given values |
200 Returns the largest of the given values |
197 """ |
201 """ |
198 |
202 |
199 return max(values) |
203 return max(values) |
200 |
204 |
201 def select_options (self, key_values, selected_key) : |
205 def select_options (self, key_values, selected_key=None) : |
202 """ |
206 """ |
203 Render a series of <option> tags for <select> |
207 Render a series of <option> tags for <select>. |
|
208 |
|
209 The given key_values is an iterable of (key, value) pairs, key may be None if it's the same as value. |
204 """ |
210 """ |
205 |
211 |
206 return '\n'.join( |
212 return '\n'.join( |
207 '\t<option%s%s>%s</option>' % ( |
213 '\t<option%s%s>%s</option>' % ( |
208 ' value="%s"' % key if key != value else '', |
214 ' value="%s"' % key if key is not None else '', |
209 ' selected="selected"' if key == selected_key else '', |
215 ' selected="selected"' if (key if key is not None else value) == selected_key else '', |
210 value |
216 value |
211 ) for key, value in key_values |
217 ) for key, value in key_values |
212 ) |
218 ) |
213 |
219 |
214 def prev_date (self, date) : |
220 def prev_date (self, date) : |