From: richard Date: Sat, 12 Oct 2002 23:10:36 +0000 (+0000) Subject: expose the Date.pretty method to templating X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c190c6c50fead31bd6ad6312f8f4c00a9850c7da;p=roundup.git expose the Date.pretty method to templating git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1345 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 5bbc01a..f4a3df8 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -24,6 +24,7 @@ are given with the most recent entry first. - 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 diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 0a82a17..e7802dc 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -879,6 +879,16 @@ class DateHTMLProperty(HTMLProperty): 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 diff --git a/roundup/date.py b/roundup/date.py index 6299318..54265d1 100644 --- a/roundup/date.py +++ b/roundup/date.py @@ -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 @@ class Date: 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'''