# HG changeset patch # User casties # Date 1368608515 -7200 # Node ID 77f2478ae9718e71c7be39920640b0ad24de29cb # Parent ab836d3f96dc504eef852cd310e759086d644ce7 getDateString method to format dates in English and German. diff -r ab836d3f96dc -r 77f2478ae971 MPIWGRoot.py --- a/MPIWGRoot.py Tue May 14 17:24:30 2013 +0200 +++ b/MPIWGRoot.py Wed May 15 11:01:55 2013 +0200 @@ -14,7 +14,7 @@ from MPIWGHelper import * import updatePersonalWWW import MPIWGStaff -from SrvTxtUtils import getInt, getAt, utf8ify, refreshingImageFileIndexHtml +from SrvTxtUtils import getInt, getAt, utf8ify, refreshingImageFileIndexHtml, getDateString class MPIWGRoot(ZSQLExtendFolder): @@ -117,6 +117,11 @@ else: return False + + def getDateString(self, **args): + """Return a formatted date string.""" + return getDateString(**args) + def getSubsections(self, here=None): """return sub-navigation elements i.e. elements below sections""" diff -r ab836d3f96dc -r 77f2478ae971 SrvTxtUtils.py --- a/SrvTxtUtils.py Tue May 14 17:24:30 2013 +0200 +++ b/SrvTxtUtils.py Wed May 15 11:01:55 2013 +0200 @@ -13,7 +13,7 @@ import xml.etree.ElementTree as ET -srvTxtUtilsVersion = "1.8" +srvTxtUtilsVersion = "1.9" map_months = {'en': [u"", u"January", @@ -118,6 +118,23 @@ """returns the name of the month mon in the language lang""" return map_months[lang][mon] + +def getDateString(date=None, lang='en', withYear=True, abbrev=False): + """Return formatted date string.""" + ds = None + if lang.lower() == 'en': + ds = "%s, %s"%(getMonthName(date.month(), lang), date.day()) + if withYear: + ds += " %s"%date.year() + + elif lang.lower() == 'de': + ds = "%s.%s."%(date.day(), date.month()) + if withYear: + ds += " %s"%date.year() + + return ds + + def getHttpData(url, data=None, num_tries=3, timeout=10, noExceptions=False): """returns result from url+data HTTP request""" # we do GET (by appending data to url)