當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。