diff --git a/api/templates/api_help.html b/api/templates/api_help.html index bfbc6ddd..02e4ba62 100644 --- a/api/templates/api_help.html +++ b/api/templates/api_help.html @@ -15,7 +15,18 @@

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 your website doesn't allow javascript (wordpress blogs, for example) you can use the no-script version. Copy/paste this into your site:
+
+
featured book cover
Today's Free Ebook at Unglue.it +
+
+
+ {% 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:
diff --git a/api/urls.py b/api/urls.py index c8697b19..be4aaff3 100644 --- a/api/urls.py +++ b/api/urls.py @@ -7,7 +7,14 @@ from regluit.api import resources from regluit.api.views import ApiHelpView from regluit.api.views import OPDSNavigationView, OPDSAcquisitionView from regluit.api.views import OnixView -from regluit.api.views import travisci_webhook, load_yaml, negotiate_content, widget +from regluit.api.views import ( + travisci_webhook, + load_yaml, + negotiate_content, + widget, + featured_cover, + featured_url, + ) v1_api = Api(api_name='v1') @@ -21,7 +28,9 @@ v1_api.register(resources.FreeResource()) urlpatterns = [ url(r'^help$', ApiHelpView.as_view(), name="api_help"), - url(r'^widget/(?P\w+)/$',widget,name="widget"), + url(r'^widget/(?P\w+)/$', widget, name="widget"), + url(r'^featured_cover$', featured_cover, name="featured_cover"), + url(r'^featured_url$', featured_url, name="featured_url"), 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 d423b82b..9e35a400 100755 --- a/api/views.py +++ b/api/views.py @@ -46,17 +46,21 @@ def negotiate_content(request,work_id): return HttpResponseRedirect(reverse('work', kwargs={'work_id': work_id})) +def featured_work(): + try: + 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] + return work + def widget(request, isbn): """ supply info for book panel. parameter is named isbn for historical reasons. can be isbn or work_id """ if isbn == 'featured': - try: - 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] + work = featured_work() else : if len(isbn)==10: isbn = regluit.core.isbn.convert_10_to_13(isbn) @@ -74,6 +78,14 @@ def widget(request, isbn): {'work':work, }, ) +def featured_cover(request): + work = featured_work() + return HttpResponseRedirect(work.cover_image_thumbnail()) + +def featured_url(request): + work = featured_work() + return HttpResponseRedirect(reverse('work', kwargs={'work_id': work.id})) + def load_yaml(request): if request.method == "GET": return render(request, 'load_yaml.html', { })