helpers.py
author Tero Marttila <terom@fixme.fi>
Mon, 09 Feb 2009 04:39:24 +0200
changeset 54 b65a95eb9f6b
parent 50 f13cf27a360b
child 55 5667d2bbdc50
permissions -rw-r--r--
implement browse-by-date to show a nice calendar
"""
    Some additional helpers
"""

import qmsk.web.helpers

import datetime, calendar

class Helpers (qmsk.web.helpers.Helpers) :
    """
        Our set of helpers, inheriting from base helpers
    """

    def tz_name (self, tz) :
        """
            Returns a string describing the given timezone
        """

        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()