0

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
fetzig
  • 1,642
  • 1
  • 13
  • 25

2 Answers2

0

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
fetzig
  • 1,642
  • 1
  • 13
  • 25
  • Could this somehow affect a simultaneous request of your feed in the splitsecond that your locale is set to Austrian (and hence your feed not being RFC-conform)? – Tom van Enckevort Dec 02 '10 at 14:34
0

You could use the Babel internationalization module. Look here for the format_date function that formats datetime with a specific locale.

Tom van Enckevort
  • 4,170
  • 1
  • 25
  • 40