[1.2.X] Fixed #14888 -- Removing duplicated code in serialisers. Thanks to eric.fortin.
Backport of [15163] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15164 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d065e7eed2
commit
989486d05d
|
@ -31,9 +31,9 @@ class Serializer(object):
|
||||||
"""
|
"""
|
||||||
self.options = options
|
self.options = options
|
||||||
|
|
||||||
self.stream = options.get("stream", StringIO())
|
self.stream = options.pop("stream", StringIO())
|
||||||
self.selected_fields = options.get("fields")
|
self.selected_fields = options.pop("fields", None)
|
||||||
self.use_natural_keys = options.get("use_natural_keys", False)
|
self.use_natural_keys = options.pop("use_natural_keys", False)
|
||||||
|
|
||||||
self.start_serialization()
|
self.start_serialization()
|
||||||
for obj in queryset:
|
for obj in queryset:
|
||||||
|
|
|
@ -18,9 +18,6 @@ class Serializer(PythonSerializer):
|
||||||
internal_use_only = False
|
internal_use_only = False
|
||||||
|
|
||||||
def end_serialization(self):
|
def end_serialization(self):
|
||||||
self.options.pop('stream', None)
|
|
||||||
self.options.pop('fields', None)
|
|
||||||
self.options.pop('use_natural_keys', None)
|
|
||||||
simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
|
simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
|
||||||
|
|
||||||
def getvalue(self):
|
def getvalue(self):
|
||||||
|
|
|
@ -38,9 +38,6 @@ class Serializer(PythonSerializer):
|
||||||
super(Serializer, self).handle_field(obj, field)
|
super(Serializer, self).handle_field(obj, field)
|
||||||
|
|
||||||
def end_serialization(self):
|
def end_serialization(self):
|
||||||
self.options.pop('stream', None)
|
|
||||||
self.options.pop('fields', None)
|
|
||||||
self.options.pop('use_natural_keys', None)
|
|
||||||
yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
|
yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
|
||||||
|
|
||||||
def getvalue(self):
|
def getvalue(self):
|
||||||
|
|
Loading…
Reference in New Issue