django.utils.xmlutils.SimplerXMLGenerator

Here are the examples of the python api django.utils.xmlutils.SimplerXMLGenerator taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

24 Examples 7

Example 1

Project: talk.org Source File: xml_serializer.py
Function: start_serialization
    def start_serialization(self):
        """
        Start serialization -- open the XML docuement and the root element.
        """
        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
        self.xml.startDocuement()
        self.xml.startElement("django-objects", {"version" : "1.0"})

Example 2

Project: GAE-Bulk-Mailer Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement("rss", self.rss_attributes())
        handler.startElement("channel", self.root_attributes())
        self.add_root_elements(handler)
        self.write_items(handler)
        self.endChannelElement(handler)
        handler.endElement("rss")

Example 3

Project: GAE-Bulk-Mailer Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement('feed', self.root_attributes())
        self.add_root_elements(handler)
        self.write_items(handler)
        handler.endElement("feed")

Example 4

Project: edison Source File: emitters.py
Function: render
    def render(self, request):
        stream = StringIO.StringIO()

        xml = SimplerXMLGenerator(stream, "utf-8")
        xml.startDocuement()
        xml.startElement("response", {})

        self._to_xml(xml, self.construct())

        xml.endElement("response")
        xml.endDocuement()

        return stream.getvalue()

Example 5

Project: PyClassLessons Source File: xml_serializer.py
    def start_serialization(self):
        """
        Start serialization -- open the XML docuement and the root element.
        """
        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
        self.xml.startDocuement()
        self.xml.startElement("django-objects", {"version": "1.0"})

Example 6

Project: snowy Source File: emitters.py
Function: render
    def render(self, request):
        stream = StringIO.StringIO()
        
        xml = SimplerXMLGenerator(stream, "utf-8")
        xml.startDocuement()
        xml.startElement("response", {})
        
        self._to_xml(xml, self.construct())
        
        xml.endElement("response")
        xml.endDocuement()
        
        return stream.getvalue()

Example 7

Project: xadmin Source File: export.py
    def get_xml_export(self, context):
        results = self._get_objects(context)
        stream = StringIO.StringIO()

        xml = SimplerXMLGenerator(stream, "utf-8")
        xml.startDocuement()
        xml.startElement("objects", {})

        self._to_xml(xml, results)

        xml.endElement("objects")
        xml.endDocuement()

        return stream.getvalue().split('\n')[1]

Example 8

Project: syndication-view Source File: feedgenerator.py
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement(u"rss", self.rss_attributes())
        handler.startElement(u"channel", self.root_attributes())
        self.add_root_elements(handler)
        self.write_items(handler)
        self.endChannelElement(handler)
        handler.endElement(u"rss")

Example 9

Project: syndication-view Source File: feedgenerator.py
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement(u'feed', self.root_attributes())
        self.add_root_elements(handler)
        self.write_items(handler)
        handler.endElement(u"feed")

Example 10

Project: devil Source File: xmlmapper.py
Function: format_data
    def _format_data(self, data, charset):
        """ Format data into XML. """

        if data is None or data == '':
            return u''

        stream = StringIO.StringIO()
        xml = SimplerXMLGenerator(stream, charset)
        xml.startDocuement()
        xml.startElement(self._root_element_name(), {})
        self._to_xml(xml, data)
        xml.endElement(self._root_element_name())
        xml.endDocuement()
        return stream.getvalue()

Example 11

Project: cadasta-platform Source File: renderers.py
Function: render
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders *obj* into serialized XML.
        """
        # if data is None:
        #     return ''
        # elif isinstance(data, six.string_types):
        #     return data

        stream = StringIO()

        xml = SimplerXMLGenerator(stream, self.charset)
        xml.startDocuement()
        xml.startElement(self.root_node, {'xmlns': self.xmlns})

        self._to_xml(xml, data)
        xml.endElement(self.root_node)
        xml.endDocuement()
        return stream.getvalue()

Example 12

Project: django-roa Source File: serializers.py
Function: start_serialization
    def start_serialization(self):
        """
        Start serialization -- open the XML docuement and the root element.
        """
        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", DEFAULT_CHARSET))
        self.xml.startDocuement()
        self.xml.startElement("django-test", {"version" : "1.0"})

Example 13

Project: feedhq Source File: renderers.py
Function: render
    def render(self, data, accepted_media_type=None, renderer_context=None):
        if data is None:
            return ''

        stream = StringIO()
        xml = SimplerXMLGenerator(stream, "utf-8")
        xml.startDocuement()

        self._to_xml(xml, data)

        xml.endDocuement()
        response = stream.getvalue()

        if self.strip_declaration:
            declaration = '<?xml version="1.0" encoding="utf-8"?>'
            if response.startswith(declaration):
                response = response[len(declaration):]
        return response.strip()

Example 14

Project: django-rest-framework-xml Source File: renderers.py
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders `data` into serialized XML.
        """
        if data is None:
            return ''

        stream = StringIO()

        xml = SimplerXMLGenerator(stream, self.charset)
        xml.startDocuement()
        xml.startElement(self.root_tag_name, {})

        self._to_xml(xml, data)

        xml.endElement(self.root_tag_name)
        xml.endDocuement()
        return stream.getvalue()

Example 15

Project: theyworkforyou Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement(u"rss", {u"version": self._version})
        handler.startElement(u"channel", {})
        handler.addQuickElement(u"title", self.feed['title'])
        handler.addQuickElement(u"link", self.feed['link'])
        handler.addQuickElement(u"description", self.feed['description'])
        if self.feed['language'] is not None:
            handler.addQuickElement(u"language", self.feed['language'])
        for cat in self.feed['categories']:
            handler.addQuickElement(u"category", cat)
        if self.feed['feed_copyright'] is not None:
            handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
        self.write_items(handler)
        self.endChannelElement(handler)
        handler.endElement(u"rss")

Example 16

Project: mloss Source File: wfwfeed.py
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement(u"rss", {u"version": self._version, u"xmlns:wfw": u"http://wellformedweb.org/CommentAPI/"})
        handler.startElement(u"channel", {})
        handler.addQuickElement(u"title", self.feed['title'])
        handler.addQuickElement(u"link", self.feed['link'])
        handler.addQuickElement(u"description", self.feed['description'])
        if self.feed['language'] is not None:
            handler.addQuickElement(u"language", self.feed['language'])
        for cat in self.feed['categories']:
            handler.addQuickElement(u"category", cat)
        if self.feed['feed_copyright'] is not None:
            handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
        handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii'))
        self.write_items(handler)
        self.endChannelElement(handler)
        handler.endElement(u"rss")

Example 17

Project: talk.org Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        handler.startElement(u"rss", {u"version": self._version})
        handler.startElement(u"channel", {})
        handler.addQuickElement(u"title", self.feed['title'])
        handler.addQuickElement(u"link", self.feed['link'])
        handler.addQuickElement(u"description", self.feed['description'])
        if self.feed['language'] is not None:
            handler.addQuickElement(u"language", self.feed['language'])
        for cat in self.feed['categories']:
            handler.addQuickElement(u"category", cat)
        if self.feed['feed_copyright'] is not None:
            handler.addQuickElement(u"copyright", self.feed['feed_copyright'])
        handler.addQuickElement(u"lastBuildDate", rfc2822_date(self.latest_post_date()).decode('ascii'))
        if self.feed['ttl'] is not None:
            handler.addQuickElement(u"ttl", self.feed['ttl'])
        self.write_items(handler)
        self.endChannelElement(handler)
        handler.endElement(u"rss")

Example 18

Project: talk.org Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        if self.feed['language'] is not None:
            handler.startElement(u"feed", {u"xmlns": self.ns, u"xml:lang": self.feed['language']})
        else:
            handler.startElement(u"feed", {u"xmlns": self.ns})
        handler.addQuickElement(u"title", self.feed['title'])
        handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']})
        if self.feed['feed_url'] is not None:
            handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']})
        handler.addQuickElement(u"id", self.feed['id'])
        handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('ascii'))
        if self.feed['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", self.feed['author_name'])
            if self.feed['author_email'] is not None:
                handler.addQuickElement(u"email", self.feed['author_email'])
            if self.feed['author_link'] is not None:
                handler.addQuickElement(u"uri", self.feed['author_link'])
            handler.endElement(u"author")
        if self.feed['subtitle'] is not None:
            handler.addQuickElement(u"subtitle", self.feed['subtitle'])
        for cat in self.feed['categories']:
            handler.addQuickElement(u"category", "", {u"term": cat})
        if self.feed['feed_copyright'] is not None:
            handler.addQuickElement(u"rights", self.feed['feed_copyright'])
        self.write_items(handler)
        handler.endElement(u"feed")

Example 19

Project: django-riv Source File: xml_serializer.py
Function: end_serialization
    def end_serialization(self):
        super(Serializer, self).end_serialization()
        if not self.finalize:
            return
        self.xml = SimplerXMLGenerator(self.stream, self.encoding)
        self.xml.startDocuement()
        self.xml.startElement(self.ROOT_ELEMENT, {})

        if not isinstance(self.objects, list):
            self.objects = [self.objects,]

        for object in self.objects:
            self.indent(1)
            name = self._get_xml_name(object)
            self.xml.startElement(name, {})
            self.handle_dict(object)
            self.xml.endElement(name)

        self.indent(0)
        self.xml.endElement(self.ROOT_ELEMENT)
        self.xml.endDocuement()

Example 20

Project: akvo-rsr Source File: renderers.py
Function: render
    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        In case a request is called on /api/v1/, we now redirect the call to DRF instead of
        Tastypie. The differences between DRF and Tastypie are:

        - Different names and values for several fields (see _rename_fields).

        On paginated results:
          - An additional 'meta' object containing the limit, next, previous and total_count;
          - Next and previous links do not show the domain;
          - The root tag name is 'response';
          - The tag name of the results is 'objects';
          - The tag name for each result is 'object'.

        On non-paginated results:
          - The tag name of the result is 'object'.
        """
        request = renderer_context.get('request')

        if '/api/v1/' in request.path:
            if data is None:
                return ''

            stream = StringIO()
            xml = SimplerXMLGenerator(stream, self.charset)
            xml.startDocuement()

            if all(k in data.keys() for k in ['count', 'next', 'previous', 'offset', 'results']):
                # Paginated result
                xml.startElement("response", {})
                data = _convert_data_for_tastypie(request, renderer_context['view'], data)
                self._to_xml(xml, data)
                xml.endElement("response")
            else:
                # Non-paginated result
                xml.startElement("object", {})
                self._to_xml(xml, _rename_fields([data])[0])
                xml.endElement("object")

            xml.endDocuement()
            return stream.getvalue()
        elif isinstance(data, dict) and 'offset' in data.keys():
            data.pop('offset')

        return XMLRenderer().render(data, accepted_media_type, renderer_context)

Example 21

Project: aemanager Source File: models.py
    def backup_objects(self):
        models = [Address, Contact, Contract, PhoneNumber, Project, Proposal, ProposalRow, Invoice, InvoiceRow, Expense]

        self.xml = SimplerXMLGenerator(self.stream, settings.DEFAULT_CHARSET)
        self.xml.startDocuement()
        self.xml.startElement("aemanager", {"version" : common()['version']})

        for model in models:
            for object in model.objects.filter(owner=self.user):
                # do not export address of user profile
                if not(type(object) == Address and object.userprofile_set.count()):
                    self.indent(1)
                    self.xml.startElement(object._meta.object_name, {'uuid': object.uuid})
                    for field in object._meta.local_fields:
                        if field.name not in ['ownedobject_ptr']:
                            self.indent(2)
                            self.xml.startElement(field.name, {})
                            if getattr(object, field.name) is not None:
                                if type(field) == ForeignKey:
                                    related = getattr(object, field.name)
                                    if type(related) == Country:
                                        self.xml.addQuickElement("object", attrs={
                                          'country_code' : smart_unicode(related.country_code2)
                                        })
                                    else:
                                        self.xml.addQuickElement("object", attrs={
                                          'uuid' : smart_unicode(related.uuid)
                                        })
                                elif type(field) == OneToOneField:
                                    related = getattr(object, field.name)
                                    self.xml.addQuickElement("object", attrs={
                                      'uuid' : smart_unicode(related.uuid)
                                    })
                                else:
                                    self.xml.characters(field.value_to_string(object))
                            else:
                                self.xml.addQuickElement("None")
                            self.xml.endElement(field.name)

                    for field in object._meta.many_to_many:
                        self.indent(2)
                        self.xml.startElement(field.name, {})
                        for relobj in getattr(object, field.name).iterator():
                            self.indent(3)
                            self.xml.addQuickElement("object", attrs={
                              'uuid' : smart_unicode(relobj.uuid)
                            })
                        self.indent(2)
                        self.xml.endElement(field.name)

                    self.indent(1)
                    self.xml.endElement(smart_unicode(object._meta.object_name))

        self.indent(0)
        self.xml.endElement("aemanager")
        self.xml.endDocuement()

Example 22

Project: Geotrek-admin Source File: serializers.py
Function: init
    def __init__(self, request, stream):
        self.xml = SimplerXMLGenerator(stream, 'utf8')
        self.request = request
        self.stream = stream

Example 23

Project: theyworkforyou Source File: feedgenerator.py
Function: write
    def write(self, outfile, encoding):
        handler = SimplerXMLGenerator(outfile, encoding)
        handler.startDocuement()
        if self.feed['language'] is not None:
            handler.startElement(u"feed", {u"xmlns": self.ns, u"xml:lang": self.feed['language']})
        else:
            handler.startElement(u"feed", {u"xmlns": self.ns})
        handler.addQuickElement(u"title", self.feed['title'])
        handler.addQuickElement(u"link", "", {u"rel": u"alternate", u"href": self.feed['link']})
        if self.feed['feed_url'] is not None:
            handler.addQuickElement(u"link", "", {u"rel": u"self", u"href": self.feed['feed_url']})
        handler.addQuickElement(u"id", self.feed['link'])
        handler.addQuickElement(u"updated", rfc3339_date(self.latest_post_date()).decode('ascii'))
        if self.feed['author_name'] is not None:
            handler.startElement(u"author", {})
            handler.addQuickElement(u"name", self.feed['author_name'])
            if self.feed['author_email'] is not None:
                handler.addQuickElement(u"email", self.feed['author_email'])
            if self.feed['author_link'] is not None:
                handler.addQuickElement(u"uri", self.feed['author_link'])
            handler.endElement(u"author")
        if self.feed['subtitle'] is not None:
            handler.addQuickElement(u"subtitle", self.feed['subtitle'])
        for cat in self.feed['categories']:
            handler.addQuickElement(u"category", "", {u"term": cat})
        if self.feed['feed_copyright'] is not None:
            handler.addQuickElement(u"rights", self.feed['feed_copyright'])
        self.write_items(handler)
        handler.endElement(u"feed")

Example 24

Project: django-tcms Source File: models.py
    def to_xml(self, out, encoding=settings.DEFAULT_CHARSET):
        """Exports page data in a XML formated file. It stores
        page info as first item and value data following it.
        Files are base64 encoded and exported too.

        Example:
        <cms-page>
          <page path="/path/" template="homepage" description="Homepage"
                locale="en-gb" meta_title="Title" meta_description="Description"
                meta_keywords="Keywords" search_image="base64 encoded image"
                search_image_name="file name of search image"
                search_text="Search text"></page>
          <value name="heading" type="text" value="Page title"></value>
          <value name="an_image" type="image" value="bas64 enconded"></value>
          ...
        </cms-page>
        """
        xml = SimplerXMLGenerator(out=out, encoding=encoding)
        xml.startDocuement()
        xml.startElement('cms-page', {})

        # store page info in first child
        data = {'path': self.path.path, 'template': self.template,
                'description': self.description, 'locale': self.path.locale,
                'meta_title': self.meta_title,
                'meta_description': self.meta_description,
                'meta_keywords': self.meta_keywords,
                'search_text': self.search_text}
        if self.search_image: # add image content if any
            img = image_to_b64(self.search_image)
            if img is not None:
                name, content = img
                data['search_image_name'] = name
                data['search_image'] = content

        xml.startElement('page', data)
        xml.endElement('page')

        # store values
        values = self.values.values_list('name', 'type', 'value')
        for name, value_type, value in values:
            attrs = {'name': name, 'type': value_type, 'value': value}

            if value_type in TYPES_MAP:
                attrs.update(TYPES_MAP[value_type]().to_xml(value))
            xml.startElement('value', attrs)
            xml.endElement('value')

        xml.endElement('cms-page')
        xml.endDocuement()
        return out