helpers.py
changeset 60 759369a79527
parent 58 ce028d356e1f
child 62 e7ca94b94a4e
equal deleted inserted replaced
59:8ec729c5d998 60:759369a79527
     1 """
     1 """
     2     Some additional helpers
     2     Some additional helpers
     3 """
     3 """
     4 
     4 
       
     5 import datetime, calendar
       
     6 
     5 import qmsk.web.helpers
     7 import qmsk.web.helpers
     6 
     8 
     7 import datetime, calendar
     9 import preferences
     8 
    10 
     9 class Helpers (qmsk.web.helpers.Helpers) :
    11 class Helpers (qmsk.web.helpers.Helpers) :
    10     """
    12     """
    11         Our set of helpers, inheriting from base helpers
    13         Our set of helpers, inheriting from base helpers
    12     """
    14     """
    15         """
    17         """
    16             Returns a string describing the given timezone
    18             Returns a string describing the given timezone
    17         """
    19         """
    18 
    20 
    19         return str(tz)
    21         return str(tz)
    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 
    22 
    29     def fmt_month (self, date) :
    23     def fmt_month (self, date) :
    30         """
    24         """
    31             Formats a month
    25             Formats a month
    32         """
    26         """
   119         if month.month == 12 :
   113         if month.month == 12 :
   120             return 1
   114             return 1
   121 
   115 
   122         else :
   116         else :
   123             return month.month + 1
   117             return month.month + 1
       
   118     
       
   119     def fmt_time (self, time=None) :
       
   120         """
       
   121             Format given time, or current time
       
   122         """
       
   123         
       
   124         # defaults
       
   125         if not time :
       
   126             time = self.now()
   124 
   127 
       
   128         return time.strftime(self.ctx['prefs'][preferences.time_format])
       
   129 
       
   130     def fmt_date (self, date=None) :
       
   131         """
       
   132             Format given date, or current date
       
   133         """
       
   134         
       
   135         # defaults
       
   136         if not date :
       
   137             date = self.now()
       
   138 
       
   139         return date.strftime(self.ctx['prefs'][preferences.date_format])
       
   140