Ticket #5458: 20070914_patchSerializeXml4Flex.diff
File 20070914_patchSerializeXml4Flex.diff, 2.4 KB (added by , 17 years ago) |
---|
-
core/serializers/xml_serializer.py
12 12 class Serializer(base.Serializer): 13 13 """ 14 14 Serializes a QuerySet to XML. 15 - flexmode - enables easier xml parsing from Adobe Flex (HttpService+Dataprovider), no '-' in tag names, tags 'field' to '%field.name%' tag. 15 16 """ 16 17 def serialize(self, queryset, **options): 18 self.flexmode = options.get("flexmode") 19 if self.flexmode: 20 self.startelemname="django_objects" 21 else: 22 self.startelemname="django-objects" 23 return base.Serializer.serialize(self, queryset, **options) 24 17 25 def indent(self, level): 18 26 if self.options.get('indent', None) is not None: 19 27 self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent', None) * level) … … 24 32 """ 25 33 self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET)) 26 34 self.xml.startDocument() 27 self.xml.startElement( "django-objects", {"version" : "1.0"})35 self.xml.startElement(self.startelemname, {"version" : "1.0"}) 28 36 29 37 def end_serialization(self): 30 38 """ 31 39 End serialization -- end the document. 32 40 """ 33 41 self.indent(0) 34 self.xml.endElement( "django-objects")42 self.xml.endElement(self.startelemname) 35 43 self.xml.endDocument() 36 44 37 45 def start_object(self, obj): … … 60 68 ManyToManyFields) 61 69 """ 62 70 self.indent(2) 63 self.xml.startElement("field", { 71 if self.flexmode: 72 elemname = field.name 73 else: 74 elemname = "field" 75 self.xml.startElement(elemname, { 64 76 "name" : field.name, 65 "type" : field.get_internal_type() 66 })77 "type" : field.get_internal_type(), 78 }) 67 79 68 80 # Get a "string version" of the object's data (this is handled by the 69 81 # serializer base class). … … 73 85 else: 74 86 self.xml.addQuickElement("None") 75 87 76 self.xml.endElement( "field")88 self.xml.endElement(elemname) 77 89 78 90 def handle_fk_field(self, obj, field): 79 91 """