--- a/helpers.py Mon Feb 09 03:05:43 2009 +0200
+++ b/helpers.py Mon Feb 09 04:39:24 2009 +0200
@@ -2,21 +2,56 @@
Some additional helpers
"""
-# "inherit" qmsk.web's helpers
-from qmsk.web.helpers import *
+import qmsk.web.helpers
-def tz_name (tz) :
+import datetime, calendar
+
+class Helpers (qmsk.web.helpers.Helpers) :
"""
- Returns a string describing the given timezone
+ Our set of helpers, inheriting from base helpers
"""
- return str(tz)
+ def tz_name (self, tz) :
+ """
+ Returns a string describing the given timezone
+ """
-def fmt_date (date) :
- """
- Formats a date
- """
-
- # XXX: hardcoded
- return date.strftime('%Y-%m-%d')
+ return str(tz)
+ def fmt_date (self, date) :
+ """
+ Formats a date
+ """
+
+ # XXX: hardcoded
+ return date.strftime('%Y-%m-%d')
+
+ def fmt_month (self, date) :
+ """
+ Formats a month
+ """
+
+ return date.strftime('%B %Y')
+
+ def fmt_weekday (self, wday) :
+ """
+ Formats an abbreviated weekday name
+ """
+
+ return calendar.day_abbr[wday]
+
+ def build_date (self, month, mday) :
+ """
+ Returns a datetime.date for the given (month.year, month.month, mday)
+ """
+
+ return datetime.date(month.year, month.month, mday)
+
+ def is_today (self, date) :
+ """
+ checks if the given date is today
+ """
+
+ # construct current date
+ return date == self.ctx['timezone'].localize(datetime.datetime.now()).date()
+