Exemple #1
0
    def get(self, request):
        jurisdictions = E.jurisdictions(*[
            E.jurisdiction(
                *([E.id(jur.id)] + jur.xml_elem.xpath('name') + 
                [make_link('self', jur.url)])
            ) for jur in Jurisdiction.objects.all()
        ])

        services = E.services(*[
            E.service(
                #E.service_description(s['description']),
                make_link('self', urlresolvers.reverse(s['url_name'])),
                make_link('service_type', s['type_url'])
            ) for s in SERVICES if 'test' not in s or s['test']()
        ])

        return Resource([jurisdictions, services])
Exemple #2
0
    def to_full_xml_element(self, accept_language=None):
        el = deepcopy(self.xml_elem)

        el.insert(0, make_link('self', self.full_url))
        el.insert(0, E.id(self.id))

        # el.append(E.created(self.created.isoformat()))
        # el.append(E.updated(self.updated.isoformat()))

        if (
                not el.xpath('link[@rel="geography"]', namespaces=NSMAP)
                and JurisdictionGeography.objects.filter(jurisdiction=self).exists()):
            el.append(make_link('geography', self.get_absolute_url() + 'geography/'))

        self.remove_unnecessary_languages(accept_language, el)

        return el
Exemple #3
0
 def pagination_to_xml(self):
     if not self.pagination:
         return None
     el = E.pagination(
         E.offset(unicode(self.pagination['offset'])),
     )
     for linkname in ['previous_url', 'next_url']:
         url = self.pagination.get(linkname)
         if url:
             el.append(make_link(linkname.replace('_url', ''), url))
     return el
Exemple #4
0
    def to_full_xml_element(self, accept_language=None,
            fake_links=False, remove_internal_elements=False):

        el = deepcopy(self.xml_elem)

        if fake_links:
            el.insert(0, E.id('xxx.yyy/x%s' % self.id))
            el.insert(0, make_link('jurisdiction', 'http://example.org/xxx'))
            el.insert(0, make_link('self', '/xxx/yyy'))
        else:
            el.insert(0, E.id(self.full_id))
            el.insert(0, make_link('jurisdiction', self.cached_jurisdiction.full_url))
            el.insert(0, make_link('self', self.url))

        if remove_internal_elements:
            for internal_element in el.xpath('//*[namespace-uri()="' + NSMAP['protected'] + '"]'):
                internal_element.getparent().remove(internal_element)

        self.remove_unnecessary_languages(accept_language, el)

        return el