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


Python serializers.get_serializer方法代码示例

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


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

示例1: test_naive_datetime

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_naive_datetime(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)])
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt, dt) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例2: test_naive_datetime_with_microsecond

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_naive_datetime_with_microsecond(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30.405")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt.replace(microsecond=405000))

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30.405060")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)])
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt, dt) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例3: test_aware_datetime_with_microsecond

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_with_microsecond(self):
        dt = datetime.datetime(2011, 9, 1, 17, 20, 30, 405060, tzinfo=ICT)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T17:20:30.405+07:00")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt.replace(microsecond=405000))

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T17:20:30.405060+07:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)])
            self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30.405060+07:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例4: test_aware_datetime_in_utc

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_in_utc(self):
        dt = datetime.datetime(2011, 9, 1, 10, 20, 30, tzinfo=UTC)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T10:20:30Z")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T10:20:30+00:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)])
            self.assert_yaml_contains_datetime(data, "2011-09-01 10:20:30+00:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例5: test_aware_datetime_in_local_timezone

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_in_local_timezone(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30+03:00")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30+03:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)])
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30+03:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:25,代码来源:tests.py

示例6: test_naive_datetime

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_naive_datetime(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt, dt) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例7: test_naive_datetime_with_microsecond

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_naive_datetime_with_microsecond(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30.405")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt.replace(microsecond=405000))

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30.405060")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt, dt) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例8: test_aware_datetime_with_microsecond

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_with_microsecond(self):
        dt = datetime.datetime(2011, 9, 1, 17, 20, 30, 405060, tzinfo=ICT)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T17:20:30.405+07:00")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt.replace(microsecond=405000))

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T17:20:30.405060+07:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
            self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30.405060+07:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例9: test_aware_datetime_in_local_timezone

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_in_local_timezone(self):
        dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T13:20:30+03:00")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T13:20:30+03:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
            self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30+03:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例10: test_aware_datetime_in_other_timezone

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_aware_datetime_in_other_timezone(self):
        dt = datetime.datetime(2011, 9, 1, 17, 20, 30, tzinfo=ICT)

        data = serializers.serialize('python', [Event(dt=dt)])
        self.assert_python_contains_datetime(data, dt)
        obj = next(serializers.deserialize('python', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('json', [Event(dt=dt)])
        self.assert_json_contains_datetime(data, "2011-09-01T17:20:30+07:00")
        obj = next(serializers.deserialize('json', data)).object
        self.assertEqual(obj.dt, dt)

        data = serializers.serialize('xml', [Event(dt=dt)])
        self.assert_xml_contains_datetime(data, "2011-09-01T17:20:30+07:00")
        obj = next(serializers.deserialize('xml', data)).object
        self.assertEqual(obj.dt, dt)

        if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
            data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
            self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30+07:00")
            obj = next(serializers.deserialize('yaml', data)).object
            self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) 
开发者ID:nesdis,项目名称:djongo,代码行数:25,代码来源:tests.py

示例11: save_serialized_json_batch

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def save_serialized_json_batch(self, proj_dir, table_name, batch, act_set):
        """ saves a batch of data, serialized as JSON """
        JSONserializer = serializers.get_serializer('json')
        json_serializer = JSONserializer()
        filename = table_name + '-' + self.prepend_zeros(str(batch), 5) + '.json'
        file_path = proj_dir + filename
        data = json_serializer.serialize(act_set,
                                         ensure_ascii=False)
        json_output = json.dumps(data,
                                 indent=4,
                                 ensure_ascii=False)
        file = codecs.open(file_path, 'w', 'utf-8')
        # file.write(codecs.BOM_UTF8)
        file.write(json_output)
        file.close() 
开发者ID:ekansa,项目名称:open-context-py,代码行数:17,代码来源:models.py

示例12: test_get_unknown_serializer

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def test_get_unknown_serializer(self):
        """
        #15889: get_serializer('nonsense') raises a SerializerDoesNotExist
        """
        with self.assertRaises(SerializerDoesNotExist):
            serializers.get_serializer("nonsense")

        with self.assertRaises(KeyError):
            serializers.get_serializer("nonsense")

        # SerializerDoesNotExist is instantiated with the nonexistent format
        with self.assertRaises(SerializerDoesNotExist) as cm:
            serializers.get_serializer("nonsense")
        self.assertEqual(cm.exception.args, ("nonsense",)) 
开发者ID:nesdis,项目名称:djongo,代码行数:16,代码来源:tests.py

示例13: register_tests

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def register_tests(test_class, method_name, test_func, exclude=()):
    """
    Dynamically create serializer tests to ensure that all registered
    serializers are automatically tested.
    """
    for format_ in serializers.get_serializer_formats():
        if format_ == 'geojson' or format_ in exclude:
            continue
        decorated_func = skipIf(
            isinstance(serializers.get_serializer(format_), serializers.BadSerializer),
            'The Python library for the %s serializer is not installed.' % format_,
        )(test_func)
        setattr(test_class, method_name % format_, partialmethod(decorated_func, format_)) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例14: save_editorial_and_pre_redaction_data

# 需要导入模块: from django.core import serializers [as 别名]
# 或者: from django.core.serializers import get_serializer [as 别名]
def save_editorial_and_pre_redaction_data(self, uuid_list):
        """ Redacts uuids from a data publication for an editorial reason """
        saved_query_sets = []
        ok = True
        if not isinstance(uuid_list, list):
            uuid_list = [uuid_list]
        editorial = Editorial()
        editorial.project_uuid = self.editorial_project_uuid
        editorial.user_id = self.editorial_user_id
        if self.editorial_uuid is not None:
            editorial.uuid = self.editorial_uuid
        if self.editorial_class_uri is not None:
            editorial.class_uri = self.editorial_class_uri
        if self.editorial_label is not None:
            editorial.label = self.editorial_label
        if self.editorial_note is not None:
            editorial.note = self.editorial_note
        editorial.save()
        if editorial.uuid is not None:
            print('Preparing editorial action: ' + str(editorial.uuid))
            self.editorial_uuid = editorial.uuid
        JSONserializer = serializers.get_serializer('json')
        json_serializer = JSONserializer()
        data = LastUpdatedOrderedDict()
        for model_name in self.project_models:
            query_set = self.get_query_set(model_name, uuid_list)
            if len(query_set) > 0:
                save_ok = False
                model_data = json_serializer.serialize(query_set,
                                                       ensure_ascii=False)
                data[model_name] = model_data
                editorial.restore_json = data
                try:
                    editorial.save()
                    save_ok = True
                except:
                    print('Failed to save restore data at: ' + model_name)
                    save_ok = False
                    ok = False
                if save_ok:
                    print('Saved restore data for model: ' + model_name)
                    saved_query_sets.append(query_set)
        if ok is False:
            # we don't want to delete anything if we had a problem
            # saving the restore data
            saved_query_sets = None
        return saved_query_sets 
开发者ID:ekansa,项目名称:open-context-py,代码行数:49,代码来源:manage.py


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