implement sorel-thumbnail

uses thumbnail for all non-google covers
pull/1/head
eric 2015-08-21 17:54:39 -04:00
parent 8d80be5248
commit c34ffdd883
6 changed files with 14 additions and 7 deletions

View File

@ -16,6 +16,7 @@ from datetime import timedelta, datetime
from decimal import Decimal
from notification import models as notification
from postmonkey import PostMonkey, MailChimpException
from sorl.thumbnail import get_thumbnail
from tempfile import SpooledTemporaryFile
'''
@ -1711,16 +1712,20 @@ class Edition(models.Model):
return "%s (GLUE %s) %s" % (self.title, self.id, self.publisher)
def cover_image_small(self):
if self.cover_image:
return self.cover_image
#80 pixel high image
if self.cover_image:
im = get_thumbnail(self.cover_image, 'x80', crop='noop', quality=95)
return im.url
elif self.googlebooks_id:
return "https://encrypted.google.com/books?id=%s&printsec=frontcover&img=1&zoom=5" % self.googlebooks_id
else:
return ''
def cover_image_thumbnail(self):
#128 pixel wide image
if self.cover_image:
return self.cover_image
im = get_thumbnail(self.cover_image, '128', crop='noop', quality=95)
return im.url
elif self.googlebooks_id:
return "https://encrypted.google.com/books?id=%s&printsec=frontcover&img=1&zoom=1" % self.googlebooks_id
else:

View File

@ -204,7 +204,7 @@
</div>
</div>
<div class="listview panelfront side1 book-thumb">
<a href="{% if workid %}{% url 'work' workid %}{% else %}{% url 'googlebooks' googlebooks_id %}{% endif %}" target="_top"><img src="{% if thumbnail %}{{ thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="Book cover" title="book cover" /></a>
<a href="{% if workid %}{% url 'work' workid %}{% else %}{% url 'googlebooks' googlebooks_id %}{% endif %}" target="_top"><img src="{{ thumbnail }}" alt="Book cover" title="book cover" /></a>
</div>
<div class="listview panelfront side1 book-name">
<div class="title">

View File

@ -49,7 +49,7 @@ function put_un_in_cookie2(){
{% if work.googlebooks_id %}
<img src="{{ work.cover_image_thumbnail }}" alt="Find {{ work.title }} at Google Books" title="Find {{ work.title }} at Google Books" width="131" height="192" />
{% else %}
<img src="{% if work.cover_image_thumbnail %}{{ work.cover_image_thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
<img src="{{ work.cover_image_thumbnail }}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
{% endif %}
</a>
<div class="quicktour" style=" padding-top: 10px;padding-left: 5px;">

View File

@ -87,7 +87,7 @@
</div>
{% else %}
<div id="book-detail-img">
<img itemprop="image" src="{% if work.cover_image_thumbnail %}{{ work.cover_image_thumbnail }}{% else %}/static/images/generic_cover_larger.png{% endif %}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
<img itemprop="image" src="{{ work.cover_image_thumbnail }}" alt="{{ work.title }}" title="{{ work.title }}" width="131" height="192" />
</div>
{% endif %}
<div class="book-detail-info">

View File

@ -70,6 +70,7 @@ requests==2.6.0
requests-oauthlib==0.4.2
selenium==2.46.0
six==1.9.0
sorl-thumbnail==12.3
ssh==1.7.14
stevedore==0.4
stripe==1.9.1

View File

@ -146,7 +146,8 @@ INSTALLED_APPS = (
'notification',
'email_change',
'ckeditor',
'storages',
'storages',
'sorl.thumbnail',
# this must appear *after* django.frontend or else it overrides the
# registration templates in frontend/templates/registration
'django.contrib.admin',