Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added implementation of --indent for the XML serializer.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4733 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2a8da0a502a12d110c23bce0ac23bc96c847ee55 1 parent f9c4ce5
@freakboy3742 freakboy3742 authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 django/core/serializers/xml_serializer.py
View
9 django/core/serializers/xml_serializer.py
@@ -13,6 +13,10 @@ class Serializer(base.Serializer):
Serializes a QuerySet to XML.
"""
+ def indent(self, level):
+ if self.options.get('indent', None) is not None:
+ self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent', None) * level)
+
def start_serialization(self):
"""
Start serialization -- open the XML document and the root element.
@@ -25,6 +29,7 @@ def end_serialization(self):
"""
End serialization -- end the document.
"""
+ self.indent(0)
self.xml.endElement("django-objects")
self.xml.endDocument()
@@ -35,6 +40,7 @@ def start_object(self, obj):
if not hasattr(obj, "_meta"):
raise base.SerializationError("Non-model object (%s) encountered during serialization" % type(obj))
+ self.indent(1)
self.xml.startElement("object", {
"pk" : str(obj._get_pk_val()),
"model" : str(obj._meta),
@@ -44,6 +50,7 @@ def end_object(self, obj):
"""
Called after handling all fields for an object.
"""
+ self.indent(1)
self.xml.endElement("object")
def handle_field(self, obj, field):
@@ -51,6 +58,7 @@ def handle_field(self, obj, field):
Called to handle each field on an object (except for ForeignKeys and
ManyToManyFields)
"""
+ self.indent(2)
self.xml.startElement("field", {
"name" : field.name,
"type" : field.get_internal_type()
@@ -94,6 +102,7 @@ def _start_relational_field(self, field):
"""
Helper to output the <field> element for relational fields
"""
+ self.indent(2)
self.xml.startElement("field", {
"name" : field.name,
"rel" : field.rel.__class__.__name__,
Please sign in to comment.
Something went wrong with that request. Please try again.