make the feeds into classes
parent
6aa3e458ea
commit
8f3bf4191a
35
api/opds.py
35
api/opds.py
|
@ -17,6 +17,9 @@ FORMAT_TO_MIMETYPE = {'pdf':"application/pdf",
|
|||
'html':"text/html",
|
||||
'text':"text/html"}
|
||||
facets = ["creative_commons","active_campaigns"]
|
||||
def feeds():
|
||||
for facet in facets:
|
||||
yield globals()[facet]()
|
||||
|
||||
def text_node(tag, text):
|
||||
node = etree.Element(tag)
|
||||
|
@ -110,24 +113,30 @@ def work_node(work, domain="unglue.it", protocol="https"):
|
|||
|
||||
return node
|
||||
|
||||
def creative_commons(domain="unglue.it", protocol="https"):
|
||||
class Facet:
|
||||
title = ''
|
||||
works = None
|
||||
feed_path = ''
|
||||
description = ''
|
||||
|
||||
def feed(self):
|
||||
return opds_feed_for_works(self.works, self.feed_path, title=self.title, domain="unglue.it", protocol="https")
|
||||
|
||||
licenses = cc.LICENSE_LIST
|
||||
ccworks = models.Work.objects.filter(editions__ebooks__isnull=False,
|
||||
editions__ebooks__rights__in=licenses).distinct().order_by('-created')
|
||||
|
||||
return opds_feed_for_works(ccworks, "creative_commons", "Unglue.it Catalog: Creative Commons Books",
|
||||
domain, protocol)
|
||||
class creative_commons(Facet):
|
||||
title = "Unglue.it Catalog: Creative Commons Books"
|
||||
feed_path = "creative_commons"
|
||||
works = models.Work.objects.filter(editions__ebooks__isnull=False,
|
||||
editions__ebooks__rights__in=cc.LICENSE_LIST).distinct().order_by('-created')
|
||||
description= "These Creative Commons licensed ebooks are ready to read - the people who created them want you to read and share them."
|
||||
|
||||
def active_campaigns(domain="unglue.it", protocol="https"):
|
||||
class active_campaigns(Facet):
|
||||
"""
|
||||
return opds feed for works associated with active campaigns
|
||||
"""
|
||||
# campaigns = models.Campaign.objects.filter(status='ACTIVE').order_by('deadline')
|
||||
campaign_works = models.Work.objects.filter(campaigns__status='ACTIVE')
|
||||
return opds_feed_for_works(campaign_works, "active_campaigns",
|
||||
"Unglue.it Catalog: Books under Active Campaign",
|
||||
domain, protocol)
|
||||
title = "Unglue.it Catalog: Books under Active Campaign"
|
||||
feed_path = "active_campaigns"
|
||||
works = models.Work.objects.filter(campaigns__status='ACTIVE')
|
||||
description= "With your help we're raising money to make these books free to the world."
|
||||
|
||||
def opds_feed_for_works(works, feed_path, title="Unglue.it Catalog", domain="unglue.it", protocol="https"):
|
||||
|
||||
|
|
|
@ -3,25 +3,20 @@
|
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://www.kbcafe.com/rss/atom.xsd.xml">
|
||||
<title>Unglue.it Catalog</title>
|
||||
<id>https://unglue.it/opds</id>
|
||||
<id>https://unglue.it/api/opds/</id>
|
||||
<updated>2014-06-13T21:48:34Z</updated>
|
||||
<author>
|
||||
<name>unglue.it</name>
|
||||
<uri>https://unglue.it</uri>
|
||||
</author>
|
||||
<link rel="start" href="https://{{site.domain}}/opds" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||
<link rel="start" href="https://unglue.it/api/opds/" type="application/atom+xml;profile=opds-catalog;kind=navigation" />
|
||||
{% for feed in feeds %}
|
||||
<entry>
|
||||
<title>Creative Commons</title>
|
||||
<id>https://unglue.it/creativecommons/</id>
|
||||
<title>{{ feed.title }}</title>
|
||||
<id>https://unglue.it/{{ feed.feed_path }}/</id>
|
||||
<updated>2014-06-13T00:00:00Z</updated>
|
||||
<link href="creative_commons/" type="application/atom+xml;profile=opds-catalog;kind=acquisition" />
|
||||
<content>These Creative Commons licensed ebooks are ready to read - the people who created them want you to read and share them..</content>
|
||||
</entry>
|
||||
<entry>
|
||||
<title>Active Campaigns</title>
|
||||
<id>https://unglue.it/campaigns/ending#2</id>
|
||||
<updated>2014-06-13T00:00:00Z</updated>
|
||||
<link href="active_campaigns/" type="application/atom+xml;profile=opds-catalog;kind=acquisition"/>
|
||||
<content>With your help we're raising money to make these books free to the world.</content>
|
||||
<link href="{{ feed.feed_path }}/" type="application/atom+xml;profile=opds-catalog;kind=acquisition" />
|
||||
<content></content>
|
||||
</entry>
|
||||
{% endfor %}
|
||||
</feed>
|
|
@ -94,7 +94,7 @@ class OPDSNavigationView(TemplateView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(OPDSNavigationView, self).get_context_data(**kwargs)
|
||||
context["opds"] = opds
|
||||
context["feeds"] = opds.feeds()
|
||||
return context
|
||||
|
||||
class OPDSAcquisitionView(View):
|
||||
|
@ -102,8 +102,8 @@ class OPDSAcquisitionView(View):
|
|||
def get(self, request, *args, **kwargs):
|
||||
facet = kwargs.get('facet')
|
||||
if facet in opds.facets:
|
||||
facet_method = getattr(opds, facet)
|
||||
return HttpResponse(facet_method(),
|
||||
facet_class = getattr(opds, facet)()
|
||||
return HttpResponse(facet_class.feed(),
|
||||
content_type="application/atom+xml;profile=opds-catalog;kind=acquisition")
|
||||
else:
|
||||
return HttpResponseNotFound("invalid facet")
|
||||
|
|
Loading…
Reference in New Issue