Merge pull request #649 from Gluejar/nojs-featured-book

add support for no javascript widget
pull/1/head
Raymond Yee 2016-11-23 11:10:51 -08:00 committed by GitHub
commit 5369eb7f32
3 changed files with 40 additions and 8 deletions

View File

@ -15,7 +15,18 @@
<h3>Ebook Widgets</h3>
<p>You don't need an API key to embed Ebook (HTML) widgets. </p>
<div>Here's a widget that displays Unglue.it's featured ebook - it changes most every day! <a href="{% url 'widget' 'featured' %}">{{base_url}}{% url 'widget' 'featured' %}</a>. Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;iframe src="{{base_url}}/api/widget/featured/" width="152" height="325" frameborder="0"&gt;&lt;/iframe&gt;</textarea>
<iframe src="{{base_url}}{% url 'widget' 'featured' %}" width="152" height="325" frameborder="0"></iframe></div>
<iframe src="{{base_url}}{% url 'widget' 'featured' %}" width="152" height="325" frameborder="0"></iframe>
</div>
<div>If your website doesn't allow javascript (wordpress blogs, for example) you can use the no-script version. Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;div style="font-size:12px; width:120px; line-height:16px; padding:5px; height:220px; background-color:#fff; color:#3d4e53; border:5px solid #edf3f4;"&gt;
&lt;a href="{{base_url}}{% url 'featured_url' %}"&gt;
&lt;img width="120" height="182" src="{{base_url}}{% url 'featured_cover' %}" alt="unglue.it featured book" /&gt;
&lt;/a&gt;&lt;/div&gt;</textarea>
<div style="display:inline-block;width: 153px;">
<div style="font-size:12px; width:120px; line-height:16px; padding:5px; height:220px; background-color:#fff; color:#3d4e53; border:5px solid #edf3f4;"><a href="{% url 'featured_url' %}"><img width="120" height="182" src="{% url 'featured_cover' %}" alt="featured book cover" /></a><br />Today's Free Ebook at Unglue.it
</div>
</div>
</div>
{% if campaign %}
<div>Here's a sample widget for the book <span style="font-style: italic">{{campaign.name}}</span> with ISBN {{campaign_isbn}}: <a href="{% url 'widget' campaign_isbn %}">{{base_url}}{% url 'widget' campaign_isbn %}</a>. Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;iframe src="{{base_url}}/api/widget/{{campaign_isbn}}/" width="152" height="325" frameborder="0"&gt;&lt;/iframe&gt;</textarea>
<iframe src="{{base_url}}{% url 'widget' campaign_isbn %}" width="152" height="325" frameborder="0"></iframe>

View File

@ -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<isbn>\w+)/$',widget,name="widget"),
url(r'^widget/(?P<isbn>\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<facet>.*)/$", OPDSAcquisitionView.as_view(), name="opds_acqusition"),
url(r"^onix/(?P<facet>.*)/$", OnixView.as_view(), name="onix"),

View File

@ -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', { })