1 """ |
1 """ |
2 Some additional helpers |
2 Some additional helpers |
3 """ |
3 """ |
4 |
4 |
5 # "inherit" qmsk.web's helpers |
5 import qmsk.web.helpers |
6 from qmsk.web.helpers import * |
|
7 |
6 |
8 def tz_name (tz) : |
7 import datetime, calendar |
|
8 |
|
9 class Helpers (qmsk.web.helpers.Helpers) : |
9 """ |
10 """ |
10 Returns a string describing the given timezone |
11 Our set of helpers, inheriting from base helpers |
11 """ |
12 """ |
12 |
13 |
13 return str(tz) |
14 def tz_name (self, tz) : |
|
15 """ |
|
16 Returns a string describing the given timezone |
|
17 """ |
14 |
18 |
15 def fmt_date (date) : |
19 return str(tz) |
16 """ |
|
17 Formats a date |
|
18 """ |
|
19 |
|
20 # XXX: hardcoded |
|
21 return date.strftime('%Y-%m-%d') |
|
22 |
20 |
|
21 def fmt_date (self, date) : |
|
22 """ |
|
23 Formats a date |
|
24 """ |
|
25 |
|
26 # XXX: hardcoded |
|
27 return date.strftime('%Y-%m-%d') |
|
28 |
|
29 def fmt_month (self, date) : |
|
30 """ |
|
31 Formats a month |
|
32 """ |
|
33 |
|
34 return date.strftime('%B %Y') |
|
35 |
|
36 def fmt_weekday (self, wday) : |
|
37 """ |
|
38 Formats an abbreviated weekday name |
|
39 """ |
|
40 |
|
41 return calendar.day_abbr[wday] |
|
42 |
|
43 def build_date (self, month, mday) : |
|
44 """ |
|
45 Returns a datetime.date for the given (month.year, month.month, mday) |
|
46 """ |
|
47 |
|
48 return datetime.date(month.year, month.month, mday) |
|
49 |
|
50 def is_today (self, date) : |
|
51 """ |
|
52 checks if the given date is today |
|
53 """ |
|
54 |
|
55 # construct current date |
|
56 return date == self.ctx['timezone'].localize(datetime.datetime.now()).date() |
|
57 |