Ticket #5458: 20070914_patchSerializeXml4Flex.diff

File 20070914_patchSerializeXml4Flex.diff, 2.4 KB (added by trebor74hr@…, 17 years ago)

patch described in the ticket

  • core/serializers/xml_serializer.py

     
    1212class Serializer(base.Serializer):
    1313    """
    1414    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.
    1516    """
    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       
    1725    def indent(self, level):
    1826        if self.options.get('indent', None) is not None:
    1927            self.xml.ignorableWhitespace('\n' + ' ' * self.options.get('indent', None) * level)
     
    2432        """
    2533        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
    2634        self.xml.startDocument()
    27         self.xml.startElement("django-objects", {"version" : "1.0"})
     35        self.xml.startElement(self.startelemname, {"version" : "1.0"})
    2836
    2937    def end_serialization(self):
    3038        """
    3139        End serialization -- end the document.
    3240        """
    3341        self.indent(0)
    34         self.xml.endElement("django-objects")
     42        self.xml.endElement(self.startelemname)
    3543        self.xml.endDocument()
    3644
    3745    def start_object(self, obj):
     
    6068        ManyToManyFields)
    6169        """
    6270        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, {
    6476            "name" : field.name,
    65             "type" : field.get_internal_type()
    66         })
     77            "type" : field.get_internal_type(),
     78            })
    6779
    6880        # Get a "string version" of the object's data (this is handled by the
    6981        # serializer base class).
     
    7385        else:
    7486            self.xml.addQuickElement("None")
    7587
    76         self.xml.endElement("field")
     88        self.xml.endElement(elemname)
    7789
    7890    def handle_fk_field(self, obj, field):
    7991        """
Back to Top