From 5eabbbb4d2a70bdcc6e4c366bb061ad9ca1ec948 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 24 Aug 2016 15:43:28 -0400 Subject: [PATCH] implement versions in api --- api/opds.py | 41 ++++++++++++++++++++++++----------------- core/bookloader.py | 2 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/api/opds.py b/api/opds.py index 297d6a8b..f6cde35f 100644 --- a/api/opds.py +++ b/api/opds.py @@ -84,25 +84,29 @@ def work_node(work, facet=None): node.append(text_node('updated', work.first_ebook().created.isoformat())) # 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: - 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 - link_rel = "http://opds-spec.org/acquisition/open-access" - link_node.attrib.update({"href":add_query_component(ebook.download_url, "feed=opds"), - "rel":link_rel, - "{http://purl.org/dc/terms/}rights": str(ebook.rights)}) - if ebook.is_direct(): - link_node.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "") - else: - """ indirect acquisition, i.e. google books """ - link_node.attrib["type"] = "text/html" - indirect = etree.Element("{http://opds-spec.org/}indirectAcquisition",) - indirect.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "") - link_node.append(indirect) - - node.append(link_node) + # 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_node.attrib.update({"href":add_query_component(ebook.download_url, "feed=opds"), + "rel":link_rel, + "{http://purl.org/dc/terms/}rights": str(ebook.rights)}) + if ebook.is_direct(): + link_node.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "") + else: + """ indirect acquisition, i.e. google books """ + link_node.attrib["type"] = "text/html" + indirect = etree.Element("{http://opds-spec.org/}indirectAcquisition",) + indirect.attrib["type"] = FORMAT_TO_MIMETYPE.get(ebook.format, "") + link_node.append(indirect) + if ebook.version_label: + link_node.attrib.update({"{http://schema.org/}version": ebook.version_label}) + node.append(link_node) # get the cover -- assume jpg? @@ -237,6 +241,9 @@ def opds_feed_for_work(work_id): works=models.Work.objects.filter(id=work_id) except models.Work.DoesNotExist: works=models.Work.objects.none() + except ValueError: + # not a valid work_id + works=models.Work.objects.none() self.works=works self.title='Unglue.it work #%s' % work_id self.feed_path='' diff --git a/core/bookloader.py b/core/bookloader.py index a02b21f8..bb5468b6 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -902,7 +902,7 @@ def load_from_yaml(yaml_url, test_mode=False): rights = cc.match_license(metadata.rights), format = ebook_format, edition = edition, - # version = metadata._version + version = metadata._version ) return work.id