コード例 #1
0
ファイル: views.py プロジェクト: uq-eresearch/uqam
def atom_feed(request, encoding='utf-8', mimetype='application/atom+xml'):
    feed_attrs = {u"xmlns": u"http://www.w3.org/2005/Atom",
                  u"xmlns:fh": u"http://purl.org/syndication/history/1.0"}
    collections = Collection.objects.filter(is_public=True)
    site = Site.objects.get(id=1)

    updated = collections.order_by('-updated')[0].updated
    feed_id = get_site_url(site, reverse('atom_feed'))

    output = StringIO.StringIO()
    handler = SimplerXMLGenerator(output, encoding)
    handler.startDocument()
    handler.startElement(u"feed", feed_attrs)

    # Required Attributes
    handler.addQuickElement(u"id", feed_id)
    handler.addQuickElement(u"title", u"UQ Anthropology Museum Sub-collections")
    handler.addQuickElement(u"updated", rfc3339_date(updated).decode('utf-8'))

    # A complete feed, so remote client will monitor for deletes/updates
    handler.addQuickElement(u"fh:complete")

    # Optional
    handler.addQuickElement(u"link", attrs={
        u'rel': u'alternate',
        u'href': get_site_url(site, reverse('collections_home')),
        u'type': u'html'
        })

    for collection in collections:
        entry_id = get_site_url(site, collection.get_absolute_url())
        entry_updated = rfc3339_date(collection.updated).decode('utf-8')

        handler.startElement(u"entry", {})
        handler.addQuickElement(u"id", entry_id)
        handler.addQuickElement(u"title", collection.title)
        handler.addQuickElement(u'updated', entry_updated)
        handler.addQuickElement(u'link', attrs={
            u'rel': u'alternate',
            u'href': get_site_url(site, collection.get_atom_url()),
            u'type': u'application/atom+xml'
            })

        handler.endElement(u'entry')

    handler.endElement(u'feed')

    atom = output.getvalue()
    response = HttpResponse(atom, mimetype=mimetype)
    return response
コード例 #2
0
ファイル: models.py プロジェクト: uq-eresearch/uqam
    def _add_spatial(self, handler, site):
        for place in self.get_places():
            place_url = get_site_url(site, place.get_absolute_url())
            handler.addQuickElement(u'link', attrs={
                u'rel': u'http://purl.org/dc/terms/spatial',
                u'href': place_url,
                u'title': unicode(place)
                })

            if place.latitude is not None:
                handler.addQuickElement(u'georss:point',
                    unicode(place.latitude) + u" " + unicode(place.longitude)
                )
コード例 #3
0
ファイル: models.py プロジェクト: uq-eresearch/uqam
    def as_atom(self, encoding='utf-8'):
        """
        Serialise to an Atom format

        Uses the profile from http://dataspace.metadata.net/doc/atom
        """
        syndication = Syndication.objects.get(id=1)
        output = StringIO.StringIO()
        site = Site.objects.get(id=1)

        link = get_site_url(site, self.get_absolute_url())
        site_id = get_site_url(site, "/")

        handler = SimplerXMLGenerator(output, encoding)
        handler.startDocument()
        handler.startElement(u"entry", self.entry_attributes())
        handler.addQuickElement(u"id", link)
        handler.addQuickElement(u"title", self.title)
        handler.addQuickElement(u'content', self.description, {'type': 'html'})
        if self.date_published:
            handler.addQuickElement(u"published", rfc3339_date(self.date_published).decode('utf-8'))
        if self.last_published:
            handler.addQuickElement(u"updated", rfc3339_date(self.last_published).decode('utf-8'))

        handler.addQuickElement(u"link", attrs={
                u'href':  'http://purl.org/dc/dcmitype/Collection',
                u'rel':   'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
                u'title': 'Collection'})

        handler.addQuickElement(u"rights", self.rights)
        handler.startElement(u"rdfa:meta",
                {u'property': u'http://purl.org/dc/terms/accessRights',
                    u'content': self.access_rights})
        handler.endElement(u"rdfa:meta")

        handler.addQuickElement(u'link', attrs={
                u'rel': u'http://purl.org/dc/terms/publisher',
                u'href': syndication.curator_href,
                u'title': syndication.curator_name
            })

        handler.startElement(u"source", {})
        handler.addQuickElement(u"id", site_id)
        handler.addQuickElement(u"title", site.name)
        handler.startElement(u"author", {})
        handler.addQuickElement(u"name", self.author.get_full_name())
        handler.addQuickElement(u"email", self.author.email)
        handler.endElement(u"author")
        handler.endElement(u"source")

        handler.startElement(u"link",
                {u"rel": "http://xmlns.com/foaf/0.1/page",
                 u"href": link})
        handler.endElement(u"link")

        handler.addQuickElement(u'category', attrs={
            u'term': u'http://purl.org/asc/1297.0/2008/for/1601',
            u'scheme': u'http://purl.org/asc/1297.0/2008/for/',
            u'label': u'1601 Anthropology'
            })

        # Published control
        draft = u'no' if self.is_public else u'yes'
        handler.startElement(u'app:control',
            {u'xmlns:app': u'http://www.w3.org/2007/app'})
        handler.addQuickElement(u'app:draft', draft)
        handler.endElement(u'app:control')

        self._add_categories(handler, site)
        self._add_spatial(handler, site)

        handler.endElement(u"entry")

        return output.getvalue()