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.
|
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.
|
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
|
Develop
|
||||||
-------
|
-------
|
||||||
|
|
14
api/onix.py
14
api/onix.py
|
@ -2,6 +2,9 @@ import datetime
|
||||||
import pytz
|
import pytz
|
||||||
import re
|
import re
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
|
from django.core.paginator import Paginator, InvalidPage
|
||||||
|
|
||||||
from regluit.core import models
|
from regluit.core import models
|
||||||
from regluit.core.cc import ccinfo
|
from regluit.core.cc import ccinfo
|
||||||
from regluit.bisac import Bisac
|
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" />
|
<ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" />
|
||||||
"""
|
"""
|
||||||
bisac = Bisac()
|
bisac = Bisac()
|
||||||
|
WORKS_PER_PAGE = 30
|
||||||
|
|
||||||
def text_node(tag, text, attrib={}):
|
def text_node(tag, text, attrib={}):
|
||||||
node = etree.Element(tag, attrib=attrib)
|
node = etree.Element(tag, attrib=attrib)
|
||||||
node.text = text
|
node.text = text
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def onix_feed(facet, max=None):
|
def onix_feed(facet, max=None, page_number=None):
|
||||||
feed = etree.fromstring(feed_xml)
|
feed = etree.fromstring(feed_xml)
|
||||||
feed.append(header(facet))
|
feed.append(header(facet))
|
||||||
works = facet.works[0:max] if max else facet.works
|
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:
|
for work in works:
|
||||||
editions = models.Edition.objects.filter(work=work,ebooks__isnull=False)
|
editions = models.Edition.objects.filter(work=work,ebooks__isnull=False)
|
||||||
editions = facet.facet_object.filter_model("Edition",editions).distinct()
|
editions = facet.facet_object.filter_model("Edition",editions).distinct()
|
||||||
|
|
|
@ -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>
|
<dd><code><a href="{% url 'opds_acqusition' 'kw.fiction' %}">{{base_url}}{% url 'opds_acqusition' 'kw.fiction' %}</a></code></dd>
|
||||||
<dt>filtered by ungluer</dt>
|
<dt>filtered by ungluer</dt>
|
||||||
<dd><code><a href="{% url 'opds_acqusition' '@eric' %}">{{base_url}}{% url 'opds_acqusition' '@eric' %}</a></code></dd>
|
<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>
|
||||||
<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>
|
<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>
|
<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>
|
<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>
|
<h3>Identifiers with Content type negotiation</h3>
|
||||||
|
|
37
api/views.py
37
api/views.py
|
@ -216,24 +216,35 @@ class OPDSAcquisitionView(View):
|
||||||
|
|
||||||
|
|
||||||
class OnixView(View):
|
class OnixView(View):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
work = request.GET.get('work', None)
|
work = request.GET.get('work', None)
|
||||||
|
|
||||||
if work:
|
if work:
|
||||||
try:
|
try:
|
||||||
work = models.safe_get_work(work)
|
work = models.safe_get_work(work)
|
||||||
except models.Work.DoesNotExist:
|
except models.Work.DoesNotExist:
|
||||||
raise Http404
|
raise Http404
|
||||||
return HttpResponse(onix.onix_feed_for_work(work),
|
return HttpResponse(onix.onix_feed_for_work(work), content_type="text/xml")
|
||||||
content_type="text/xml")
|
|
||||||
facet = kwargs.get('facet', 'all')
|
facet = kwargs.get('facet', 'all')
|
||||||
if facet:
|
|
||||||
max = request.GET.get('max', 100)
|
if not facet:
|
||||||
try:
|
return HttpResponseBadRequest(content='No facet provided')
|
||||||
max = int(max)
|
|
||||||
except:
|
max_records = request.GET.get('max', 100)
|
||||||
max = None
|
|
||||||
facet_class = opds.get_facet_class(facet)()
|
try:
|
||||||
return HttpResponse(onix.onix_feed(facet_class, max),
|
max_records = int(max_records)
|
||||||
content_type="text/xml")
|
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