changeset 1272:cae50587fb96

expose the Date.pretty method to templating
author Richard Jones <richard@users.sourceforge.net>
date Sat, 12 Oct 2002 23:10:36 +0000
parents 7733d5b96ef6
children 6ffd9fd8b89a
files CHANGES.txt roundup/cgi/templating.py roundup/date.py
diffstat 3 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sat Oct 12 23:10:08 2002 +0000
+++ b/CHANGES.txt	Sat Oct 12 23:10:36 2002 +0000
@@ -24,6 +24,7 @@
 - issues in 'done-cbb' are now also moved to 'chatting' on new messages
 - implemented the missing Interval.__add__
 - added ability to implement new templating utility methods
+- expose the Date.pretty method to templating
 
 
 2002-10-02 0.5.0
--- a/roundup/cgi/templating.py	Sat Oct 12 23:10:08 2002 +0000
+++ b/roundup/cgi/templating.py	Sat Oct 12 23:10:36 2002 +0000
@@ -879,6 +879,16 @@
             return interval.pretty()
         return str(interval)
 
+    def pretty(self, format='%d %B %Y'):
+        ''' Render the date in a pretty format (eg. month names, spaces).
+
+            The format string is a standard python strftime format string.
+            Note that if the day is zero, and appears at the start of the
+            string, then it'll be stripped from the output. This is handy
+            for the situatin when a date only specifies a month and a year.
+        '''
+        return self._value.pretty()
+
 class IntervalHTMLProperty(HTMLProperty):
     def plain(self):
         ''' Render a "plain" representation of the property
--- a/roundup/date.py	Sat Oct 12 23:10:08 2002 +0000
+++ b/roundup/date.py	Sat Oct 12 23:10:36 2002 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: date.py,v 1.35 2002-10-11 01:25:40 richard Exp $
+# $Id: date.py,v 1.36 2002-10-12 23:10:36 richard Exp $
 
 __doc__ = """
 Date, time and time interval handling.
@@ -206,12 +206,17 @@
         return '%4d-%02d-%02d.%02d:%02d:%02d'%(self.year, self.month, self.day,
             self.hour, self.minute, self.second)
 
-    def pretty(self):
+    def pretty(self, format='%d %B %Y'):
         ''' print up the date date using a pretty format...
+
+            Note that if the day is zero, and the day appears first in the
+            format, then the day number will be removed from output.
         '''
-        str = time.strftime('%d %B %Y', (self.year, self.month,
-            self.day, self.hour, self.minute, self.second, 0, 0, 0))
-        if str[0] == '0': return ' ' + str[1:]
+        str = time.strftime(format, (self.year, self.month, self.day,
+            self.hour, self.minute, self.second, 0, 0, 0))
+        # handle zero day by removing it
+        if format.startswith('%d') and str[0] == '0':
+            return ' ' + str[1:]
         return str
 
     def set(self, spec, offset=0, date_re=re.compile(r'''

Roundup Issue Tracker: http://roundup-tracker.org/