django feeds有错误的发布日期

时间:2010-12-02 14:04:29

标签: python django datetime localization django-piston

我有以下问题。

项目的django-piston api的handlers.py:

....
# "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")
 ...

现在看起来这会影响项目的提要(使用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>

(这是rfc符合日期,但是德国人死亡= Dienstag ==星期二),因此它无效。

所以我需要活塞api响应是德语(完成)。但是饲料的pubDate必须是英文的(不知道如何完成这个)。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

这就是诀窍。但我仍然愿意接受其他建议:)

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

答案 1 :(得分:0)

您可以使用Babel国际化模块。查看format_date以查找使用特定区域设置格式化日期时间的{{1}}函数。