Reputation: 1664
I have following problem.
handlers.py of project's django-piston api:
....
# "need" to set this for datetime.strftime()
locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')
class ItemOverviewHandler(BaseHandler):
...
@classmethod
def date(self, item):
# because of the setlocale() call the datestring is in german
# that's good
return item.somedatefield.date.strftime("%d. %B %Y")
...
now it seems like this effects the project's feeds (created with django.contrib.syndication):
def item_pubdate(self, item):
return item.pub_date #datetime field
# the rss look's like this
# that's not good
<pubDate>Die, 17 Aug 2010 14:00:00 +0200</pubDate>
(this is an rfc conform date, BUT in german Die == Dienstag == Tuesday), thus it's invalid.
So I need the piston api response to be in german (done). but pubDate of the feed has to be in english (have no idea how to accomplish this).
Any suggestions?
Upvotes: 0
Views: 800
Reputation: 4198
You could use the Babel internationalization module. Look here for the format_date
function that formats datetime with a specific locale.
Upvotes: 0
Reputation: 1664
this did the trick. but im still open for other suggestions :)
class ItemOverviewHandler(BaseHandler):
...
@classmethod
def date(self, item):
locale.setlocale(locale.LC_TIME,'de_AT.UTF-8')
date_string = item.somedatefield.date.strftime("%d. %B %Y")
locale.setlocale(locale.LC_TIME,'')
return date_string
Upvotes: 0