implement versions in api
parent
7ad0d7f494
commit
5eabbbb4d2
41
api/opds.py
41
api/opds.py
|
@ -84,25 +84,29 @@ def work_node(work, facet=None):
|
||||||
node.append(text_node('updated', work.first_ebook().created.isoformat()))
|
node.append(text_node('updated', work.first_ebook().created.isoformat()))
|
||||||
|
|
||||||
# links for all ebooks
|
# links for all ebooks
|
||||||
ebooks=facet.filter_model("Ebook",work.ebooks()) if facet else work.ebooks()
|
ebooks = facet.filter_model("Ebook",work.ebooks()) if facet else work.ebooks()
|
||||||
|
versions = set()
|
||||||
for ebook in ebooks:
|
for ebook in ebooks:
|
||||||
link_node = etree.Element("link")
|
if not ebook.version_label in versions:
|
||||||
|
versions.add(ebook.version_label)
|
||||||
|
link_node = etree.Element("link")
|
||||||
|
|
||||||
# ebook.download_url is an absolute URL with the protocol, domain, and path baked in
|
# ebook.download_url is an absolute URL with the protocol, domain, and path baked in
|
||||||
link_rel = "http://opds-spec.org/acquisition/open-access"
|
link_rel = "http://opds-spec.org/acquisition/open-access"
|
||||||
link_node.attrib.update({"href":add_query_component(ebook.download_url, "feed=opds"),
|
link_node.attrib.update({"href":add_query_component(ebook.download_url, "feed=opds"),
|
||||||
"rel":link_rel,
|
"rel":link_rel,
|
||||||
"{http://purl.org/dc/terms/}rights": str(ebook.rights)})
|
"{http://purl.org/dc/terms/}rights": str(ebook.rights)})
|
||||||
if ebook.is_direct():
|
if ebook.is_direct():
|
||||||
link_node.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "")
|
link_node.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "")
|
||||||
else:
|
else:
|
||||||
""" indirect acquisition, i.e. google books """
|
""" indirect acquisition, i.e. google books """
|
||||||
link_node.attrib["type"] = "text/html"
|
link_node.attrib["type"] = "text/html"
|
||||||
indirect = etree.Element("{http://opds-spec.org/}indirectAcquisition",)
|
indirect = etree.Element("{http://opds-spec.org/}indirectAcquisition",)
|
||||||
indirect.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "")
|
indirect.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "")
|
||||||
link_node.append(indirect)
|
link_node.append(indirect)
|
||||||
|
if ebook.version_label:
|
||||||
node.append(link_node)
|
link_node.attrib.update({"{http://schema.org/}version": ebook.version_label})
|
||||||
|
node.append(link_node)
|
||||||
|
|
||||||
# get the cover -- assume jpg?
|
# get the cover -- assume jpg?
|
||||||
|
|
||||||
|
@ -237,6 +241,9 @@ def opds_feed_for_work(work_id):
|
||||||
works=models.Work.objects.filter(id=work_id)
|
works=models.Work.objects.filter(id=work_id)
|
||||||
except models.Work.DoesNotExist:
|
except models.Work.DoesNotExist:
|
||||||
works=models.Work.objects.none()
|
works=models.Work.objects.none()
|
||||||
|
except ValueError:
|
||||||
|
# not a valid work_id
|
||||||
|
works=models.Work.objects.none()
|
||||||
self.works=works
|
self.works=works
|
||||||
self.title='Unglue.it work #%s' % work_id
|
self.title='Unglue.it work #%s' % work_id
|
||||||
self.feed_path=''
|
self.feed_path=''
|
||||||
|
|
|
@ -902,7 +902,7 @@ def load_from_yaml(yaml_url, test_mode=False):
|
||||||
rights = cc.match_license(metadata.rights),
|
rights = cc.match_license(metadata.rights),
|
||||||
format = ebook_format,
|
format = ebook_format,
|
||||||
edition = edition,
|
edition = edition,
|
||||||
# version = metadata._version
|
version = metadata._version
|
||||||
)
|
)
|
||||||
|
|
||||||
return work.id
|
return work.id
|
||||||
|
|
Loading…
Reference in New Issue