diff --git a/api/templates/api_help.html b/api/templates/api_help.html index b0fa099a..e9a06623 100644 --- a/api/templates/api_help.html +++ b/api/templates/api_help.html @@ -13,6 +13,17 @@ {% else %}

Please sign in first.

{% endif %} +

Ebook Widgets

+

You don't need an API key to embed Ebook (HTML) widgets.

+
Here's a widget that displays Unglue.it's featured ebook - it changes most every day! {{base_url}}{% url 'widget' 'featured' %}. Copy/paste this into your site:
+
+ {% if campaign %} +
Here's a sample widget for the book {{campaign.name}} with ISBN {{campaign_isbn}}: {{base_url}}{% url 'widget' campaign_isbn %}. Copy/paste this into your site:
+ + + +
+ {% endif %}

Basic API info

@@ -52,13 +63,6 @@ XML: {{campaign.name}} with ISBN {{campaign_isbn}}: {{base_url}}{% url 'widget' campaign_isbn %} - {% else %} -

Since there are currently no campaigns, there are no corresponding widgets.

- {% endif %}

OPDS Catalog Feeds

We have a basic implementation of OPDS feeds. You don't need a key to use them. The starting point is {{base_url}}{% url 'opds' %}

diff --git a/api/urls.py b/api/urls.py index 51ad4c43..5a1d9f4c 100644 --- a/api/urls.py +++ b/api/urls.py @@ -20,7 +20,7 @@ v1_api.register(resources.FreeResource()) urlpatterns = patterns('', url(r'^help$', ApiHelpView.as_view(), name="api_help"), - url(r'^widget/(?P\w+)/$','regluit.api.views.widget', name="widget"), + url(r'^widget/(?P\w+)/$','regluit.api.views.widget',name="widget"), url(r"^opds/$", OPDSNavigationView.as_view(template_name="opds.xml"), name="opds"), url(r"^opds/(?P.*)/$", OPDSAcquisitionView.as_view(), name="opds_acqusition"), url(r"^onix/(?P.*)/$", OnixView.as_view(), name="onix"), diff --git a/api/views.py b/api/views.py index 10127f2c..063ce518 100755 --- a/api/views.py +++ b/api/views.py @@ -47,25 +47,31 @@ def negotiate_content(request,work_id): return HttpResponseRedirect(reverse('work', kwargs={'work_id': work_id})) -def widget(request,isbn): +def widget(request, isbn): """ supply info for book panel. parameter is named isbn for historical reasons. can be isbn or work_id """ - - if len(isbn)==10: - isbn = regluit.core.isbn.convert_10_to_13(isbn) - if len(isbn)==13: + if isbn == 'featured': try: - identifier = models.Identifier.objects.get(type = 'isbn', value = isbn ) - work = identifier.work - except models.Identifier.DoesNotExist: - return render_to_response('widget.html', - { 'work':None,}, - context_instance=RequestContext(request) - ) - else: - work= models.safe_get_work(isbn) + work = models.Work.objects.filter(featured__isnull=False).distinct().order_by('-featured')[0] + except: + #shouldn't occur except in tests + work = models.Work.objects.all()[0] + else : + if len(isbn)==10: + isbn = regluit.core.isbn.convert_10_to_13(isbn) + if len(isbn)==13: + try: + identifier = models.Identifier.objects.get(type = 'isbn', value = isbn ) + work = identifier.work + except models.Identifier.DoesNotExist: + return render_to_response('widget.html', + { 'work':None,}, + context_instance=RequestContext(request) + ) + else: + work= models.safe_get_work(isbn) return render_to_response('widget.html', {'work':work, }, context_instance=RequestContext(request)