based on comments from Hadrien

pull/1/head
eric 2015-01-14 18:04:17 -05:00
parent 4321bd5f51
commit b5ae6f0d51
2 changed files with 19 additions and 4 deletions

View File

@ -3,7 +3,7 @@ from itertools import islice
from lxml import etree from lxml import etree
import datetime import datetime
import urlparse import urlparse
import urllib from django.utils.http import urlquote
import pytz import pytz
@ -19,7 +19,7 @@ FORMAT_TO_MIMETYPE = {'pdf':"application/pdf",
'text':"text/html"} 'text':"text/html"}
UNGLUEIT_URL= 'https://unglue.it' UNGLUEIT_URL= 'https://unglue.it'
NAVIGATION = "application/atom+xml;profile=opds-catalog;kind=navigation" ACQUISITION = "application/atom+xml;profile=opds-catalog;kind=acquisition"
FACET_RELATION = "http://opds-spec.org/facet" FACET_RELATION = "http://opds-spec.org/facet"
old_facets= ["creative_commons","active_campaigns"] old_facets= ["creative_commons","active_campaigns"]
@ -45,6 +45,11 @@ def text_node(tag, text):
node.text = text node.text = text
return node return node
def html_node(tag, html):
node = text_node(tag, html)
node.attrib.update({"{http://www.w3.org/2005/Atom}type":'html'})
return node
def add_query_component(url, qc): def add_query_component(url, qc):
""" """
add component qc to the querystring of url add component qc to the querystring of url
@ -119,6 +124,9 @@ def work_node(work):
#<dcterms:language>en</dcterms:language> #<dcterms:language>en</dcterms:language>
node.append(text_node("{http://purl.org/dc/terms/}language", work.language)) node.append(text_node("{http://purl.org/dc/terms/}language", work.language))
# description
node.append(html_node("{http://www.w3.org/2005/Atom}content", work.description))
# identifiers # identifiers
if work.identifiers.filter(type='isbn'): if work.identifiers.filter(type='isbn'):
for isbn in work.identifiers.filter(type='isbn')[0:9]: #10 should be more than enough for isbn in work.identifiers.filter(type='isbn')[0:9]: #10 should be more than enough
@ -131,6 +139,7 @@ def work_node(work):
category_node = etree.Element("category") category_node = etree.Element("category")
category_node.attrib["term"] = subject.name category_node.attrib["term"] = subject.name
node.append(category_node) node.append(category_node)
append_navlink(node, 'related', 'kw.'+ subject.name , 0, 'popular', title=subject.name)
return node return node
@ -260,8 +269,8 @@ def opds_feed_for_works(the_facet, page=None, order_by='newest'):
def append_navlink(feed, rel, path, page, order_by, group=None, active=None , title=""): def append_navlink(feed, rel, path, page, order_by, group=None, active=None , title=""):
link = etree.Element("link") link = etree.Element("link")
link.attrib.update({"rel":rel, link.attrib.update({"rel":rel,
"href": UNGLUEIT_URL + "/api/opds/" + urllib.quote(path) + '/?order_by=' + order_by + ('&page=' + unicode(page) if page!=None else ''), "href": UNGLUEIT_URL + "/api/opds/" + urlquote(path) + '/?order_by=' + order_by + ('&page=' + unicode(page) if page!=None else ''),
"type": NAVIGATION, "type": ACQUISITION,
"title": title, "title": title,
}) })
if rel == FACET_RELATION: if rel == FACET_RELATION:

View File

@ -10,6 +10,12 @@
<uri>https://unglue.it/</uri> <uri>https://unglue.it/</uri>
</author> </author>
<link rel="start" href="https://unglue.it{% url opds %}" type="application/atom+xml;profile=opds-catalog;kind=navigation" /> <link rel="start" href="https://unglue.it{% url opds %}" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
<link href="{{ feed.feed_path }}/?order_by=popular"
rel="http://opds-spec.org/featured"
type="application/atom+xml;profile=opds-catalog;kind=acquisition" />
<link href="{{ feed.feed_path }}/?order_by=popular"
rel="http://opds-spec.org/featured"
type="application/atom+xml;profile=opds-catalog;kind=acquisition" />
<entry> <entry>
<title>{{ feed.title }} - Popular</title> <title>{{ feed.title }} - Popular</title>
<id>https://unglue.it{% url opds_acqusition feed.feed_path %}?order_by=popular</id> <id>https://unglue.it{% url opds_acqusition feed.feed_path %}?order_by=popular</id>