当前位置: 首页>>代码示例>>Python>>正文


Python Serializer.format_date方法代码示例

本文整理汇总了Python中tastypie.serializers.Serializer.format_date方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.format_date方法的具体用法?Python Serializer.format_date怎么用?Python Serializer.format_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tastypie.serializers.Serializer的用法示例。


在下文中一共展示了Serializer.format_date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_format_date

# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_date [as 别名]
    def test_format_date(self):
        serializer = Serializer()
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        serializer = Serializer(datetime_formatting='iso-8601')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        serializer = Serializer(datetime_formatting='rfc-2822')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), u'16 Dec 2010')

        serializer = Serializer(datetime_formatting='random-garbage')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        # Stow.
        old_format = getattr(settings, 'TASTYPIE_DATETIME_FORMATTING', 'iso-8601')

        settings.TASTYPIE_DATETIME_FORMATTING = 'iso-8601'
        serializer = Serializer()
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        settings.TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'
        serializer = Serializer()
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), u'16 Dec 2010')

        settings.TASTYPIE_DATETIME_FORMATTING = 'random-garbage'
        serializer = Serializer()
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        # Restore.
        settings.TASTYPIE_DATETIME_FORMATTING = old_format
开发者ID:hackoder,项目名称:django-tastypie,代码行数:32,代码来源:serializers.py

示例2: test_format_date

# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import format_date [as 别名]
    def test_format_date(self):
        serializer = Serializer()
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        serializer = Serializer(datetime_formatting='iso-8601')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        serializer = Serializer(datetime_formatting='rfc-2822')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), u'16 Dec 2010')

        serializer = Serializer(datetime_formatting='random-garbage')
        self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='iso-8601'):
            serializer = Serializer()
            self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='rfc-2822'):
            serializer = Serializer()
            self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), u'16 Dec 2010')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='random-garbage'):
            serializer = Serializer()
            self.assertEqual(serializer.format_date(datetime.date(2010, 12, 16)), '2010-12-16')
开发者ID:7Geese,项目名称:django-tastypie,代码行数:26,代码来源:serializers.py


注:本文中的tastypie.serializers.Serializer.format_date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。