commit
3971286366
|
@ -10,7 +10,7 @@ contains four main applications: `core`, `frontend`, `api` and `payment` that ca
|
|||
and configured on as many ec2 instances that are needed to support traffic.
|
||||
The partitioning between these modules is not as clean as would be ideal. `payment` is particularly messy because we had to retool it twice because we had to switch from Paypal to Amazon Payments to Stripe.
|
||||
|
||||
regluit was originally developed on Django 1.3 (python 2.7) and currently runs on Django 1.8.
|
||||
regluit was originally developed on Django 1.3 (python 2.7) and currently runs on Django 1.11.
|
||||
|
||||
Develop
|
||||
-------
|
||||
|
|
16
api/onix.py
16
api/onix.py
|
@ -2,6 +2,9 @@ import datetime
|
|||
import pytz
|
||||
import re
|
||||
from lxml import etree
|
||||
|
||||
from django.core.paginator import Paginator, InvalidPage
|
||||
|
||||
from regluit.core import models
|
||||
from regluit.core.cc import ccinfo
|
||||
from regluit.bisac import Bisac
|
||||
|
@ -10,16 +13,25 @@ feed_xml = """<?xml version="1.0" encoding="UTF-8"?>
|
|||
<ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" />
|
||||
"""
|
||||
bisac = Bisac()
|
||||
WORKS_PER_PAGE = 30
|
||||
|
||||
def text_node(tag, text, attrib={}):
|
||||
node = etree.Element(tag, attrib=attrib)
|
||||
node.text = text
|
||||
return node
|
||||
|
||||
def onix_feed(facet, max=None):
|
||||
def onix_feed(facet, max=None, page_number=None):
|
||||
feed = etree.fromstring(feed_xml)
|
||||
feed.append(header(facet))
|
||||
works = facet.works[0:max] if max else facet.works
|
||||
|
||||
if page_number is not None:
|
||||
try:
|
||||
p = Paginator(works, WORKS_PER_PAGE)
|
||||
works = p.page(page_number)
|
||||
except InvalidPage:
|
||||
works = []
|
||||
|
||||
for work in works:
|
||||
editions = models.Edition.objects.filter(work=work,ebooks__isnull=False)
|
||||
editions = facet.facet_object.filter_model("Edition",editions).distinct()
|
||||
|
@ -209,4 +221,4 @@ def product(edition, facet=None):
|
|||
price_node.append(text_node("PriceAmount", '0.00')) #retail excluding tax
|
||||
price_node.append(text_node("CurrencyCode", 'USD')) #retail excluding tax
|
||||
return product_node
|
||||
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ class Facet:
|
|||
|
||||
def get_facet_facet(facet_path):
|
||||
class Facet_Facet(Facet):
|
||||
|
||||
|
||||
def __init__(self, facet_path=facet_path):
|
||||
self.feed_path = facet_path
|
||||
self.facet_object = facets.get_facet_object(facet_path)
|
||||
|
@ -344,4 +344,4 @@ def append_navlink(feed, rel, path, page, order_by, group=None, active=None , ti
|
|||
link.attrib['{http://opds-spec.org/}facetGroup'] = group
|
||||
if active:
|
||||
link.attrib['{http://opds-spec.org/}activeFacet'] = 'true'
|
||||
feed.append(link)
|
||||
feed.append(link)
|
||||
|
|
|
@ -89,11 +89,13 @@ XML: <a href="/api/v1/identifier/?format=xml&api_key={{api_key}}&usernam
|
|||
<dd><code><a href="{% url 'opds_acqusition' 'kw.fiction' %}">{{base_url}}{% url 'opds_acqusition' 'kw.fiction' %}</a></code></dd>
|
||||
<dt>filtered by ungluer</dt>
|
||||
<dd><code><a href="{% url 'opds_acqusition' '@eric' %}">{{base_url}}{% url 'opds_acqusition' '@eric' %}</a></code></dd>
|
||||
<dt>filtered by having a Project Gutenberg or DOAB identifier (doab, gtbg)</dt>
|
||||
<dd><code><a href="{% url 'opds_acqusition' 'doab/-gtbg' %}">{{base_url}}{% url 'opds_acqusition' 'doab/-gtbg' %}</a></code></dd>
|
||||
</p>
|
||||
<p>There's also an OPDS record available for every work on unglue.it. For example, requesting, <code><a href="{% url 'opds_acqusition' 'all'%}?work=13950">{{base_url}}{% url 'opds_acqusition' 'all'%}?work=13950</a></code> get you to the web page or opds record for <i>A Christmas Carol</i>.</p>
|
||||
|
||||
<h3>ONIX Catalog Feeds</h3>
|
||||
<p>There is an <a href="http://www.editeur.org/12/about-release-3.0/">ONIX 3.0</a> feed corresponding to every facet of our <a href="{% url 'free' %}">free ebook lists</a>. You don't need a key to use them. There is a maximum of 100 books per result you can change with the max parameter. For example, here are the <a href="{% url 'onix' 'by-nc-nd/epub' %}">first hundred CC BY-ND-ND licensed books available in EPUB.</a></p>
|
||||
<p>There is an <a href="http://www.editeur.org/12/about-release-3.0/">ONIX 3.0</a> feed corresponding to every facet of our <a href="{% url 'free' %}">free ebook lists</a>. You don't need a key to use them. There is a maximum of 100 books per result you can change with the <code>max</code> parameter. For example, here are the <a href="{% url 'onix' 'by-nc-nd/epub' %}?max=20">first twenty CC BY-ND-ND licensed books available in EPUB.</a> Pages of 30 records each are available via the <code>page</code> parameter. Here's the <a href="{% url 'onix' 'doab' %}?page=1">first page of books from the Directory of Open Access Books.</a></p>
|
||||
<p>There's also an ONIX record available for every free ebook on unglue.it. For example, here is <a href="{% url 'onix_all' %}?work=140086"><i>Issues in Open Research Data</i></a>.</p>
|
||||
|
||||
<h3>Identifiers with Content type negotiation</h3>
|
||||
|
|
41
api/views.py
41
api/views.py
|
@ -216,24 +216,35 @@ class OPDSAcquisitionView(View):
|
|||
|
||||
|
||||
class OnixView(View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
work = request.GET.get('work', None)
|
||||
|
||||
if work:
|
||||
try:
|
||||
work=models.safe_get_work(work)
|
||||
work = models.safe_get_work(work)
|
||||
except models.Work.DoesNotExist:
|
||||
raise Http404
|
||||
return HttpResponse(onix.onix_feed_for_work(work),
|
||||
content_type="text/xml")
|
||||
facet = kwargs.get('facet', 'all')
|
||||
if facet:
|
||||
max = request.GET.get('max', 100)
|
||||
try:
|
||||
max = int(max)
|
||||
except:
|
||||
max = None
|
||||
facet_class = opds.get_facet_class(facet)()
|
||||
return HttpResponse(onix.onix_feed(facet_class, max),
|
||||
content_type="text/xml")
|
||||
raise Http404
|
||||
return HttpResponse(onix.onix_feed_for_work(work), content_type="text/xml")
|
||||
|
||||
facet = kwargs.get('facet', 'all')
|
||||
|
||||
if not facet:
|
||||
return HttpResponseBadRequest(content='No facet provided')
|
||||
|
||||
max_records = request.GET.get('max', 100)
|
||||
|
||||
try:
|
||||
max_records = int(max_records)
|
||||
except Exception:
|
||||
max_records = None
|
||||
|
||||
facet_class = opds.get_facet_class(facet)()
|
||||
page = request.GET.get('page', None)
|
||||
try:
|
||||
page = int(page)
|
||||
except:
|
||||
page = None
|
||||
|
||||
feed = onix.onix_feed(facet_class, max_records, page_number=page)
|
||||
return HttpResponse(feed, content_type="text/xml")
|
||||
|
||||
|
|
Loading…
Reference in New Issue