From: Jan Szejko Date: Fri, 22 Dec 2017 13:10:25 +0000 (+0100) Subject: simple covers for app X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/ff599b825d16d3e6b1edbf263bba01bdbbf0f11f?ds=inline simple covers for app --- diff --git a/src/api/handlers.py b/src/api/handlers.py index f7b30864d..88fa1c3db 100644 --- a/src/api/handlers.py +++ b/src/api/handlers.py @@ -150,9 +150,8 @@ class BookDetails(object): return MEDIA_BASE + book.cover_api_thumb.url if book.cover_api_thumb else '' @classmethod - def cover_source_image(cls, book): - url = book.cover_source() - return url.rstrip('/') + '/file/' + def simple_cover(cls, book): + return MEDIA_BASE + book.simple_cover.url if book.simple_cover else '' class BookDetailHandler(BaseHandler, BookDetails): @@ -162,7 +161,7 @@ class BookDetailHandler(BaseHandler, BookDetails): """ allowed_methods = ['GET'] fields = ['title', 'parent', 'children'] + Book.formats + [ - 'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'fragment_data'] + [ + 'media', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'simple_cover', 'fragment_data'] + [ category_plural[c] for c in book_tag_categories] @piwik_track @@ -305,7 +304,7 @@ class QuerySetProxy(models.QuerySet): class FilterBooksHandler(AnonymousBooksHandler): fields = book_tag_categories + [ - 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'slug', 'key', 'cover_source_image'] + 'href', 'title', 'url', 'cover', 'cover_thumb', 'simple_thumb', 'slug', 'key'] def read(self, request): key_sep = '$' diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 8b28f1c43..911f857c3 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -253,6 +253,15 @@ class BuildCoverApiThumb(BuildEbook): return WLNoBoxCover(wldoc.book_info, height=500).output_file() +@BuildEbook.register('simple_cover') +@task(ignore_result=True) +class BuildSimpleCover(BuildEbook): + @classmethod + def transform(cls, wldoc, fieldfile): + from librarian.cover import WLNoBoxCover + return WLNoBoxCover(wldoc.book_info, height=1000).output_file() + + # not used, but needed for migrations class OverwritingFieldFile(FieldFile): """ diff --git a/src/catalogue/migrations/0021_auto_20171222_1404.py b/src/catalogue/migrations/0021_auto_20171222_1404.py new file mode 100644 index 000000000..845dc6969 --- /dev/null +++ b/src/catalogue/migrations/0021_auto_20171222_1404.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import catalogue.fields +import catalogue.models.book + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0020_book_cover_api_thumb'), + ] + + operations = [ + migrations.AddField( + model_name='book', + name='simple_cover', + field=catalogue.fields.EbookField(b'simple_cover', max_length=255, upload_to=catalogue.models.book.UploadToPath(b'book/cover_simple/%s.jpg'), null=True, verbose_name='cover for mobile app', blank=True), + ), + migrations.AlterField( + model_name='book', + name='cover_api_thumb', + field=catalogue.fields.EbookField(b'cover_api_thumb', max_length=255, upload_to=catalogue.models.book.UploadToPath(b'book/cover_api_thumb/%s.jpg'), null=True, verbose_name='cover thumbnail for mobile app', blank=True), + ), + ] diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index cdb110045..0f664c42d 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -42,7 +42,8 @@ class UploadToPath(object): _cover_upload_to = UploadToPath('book/cover/%s.jpg') _cover_thumb_upload_to = UploadToPath('book/cover_thumb/%s.jpg') -_cover_api_thumb_opload_to = UploadToPath('book/cover_api_thumb/%s.jpg') +_cover_api_thumb_upload_to = UploadToPath('book/cover_api_thumb/%s.jpg') +_simple_cover_upload_to = UploadToPath('book/cover_simple/%s.jpg') def _ebook_upload_to(upload_path): @@ -81,9 +82,14 @@ class Book(models.Model): upload_to=_cover_thumb_upload_to, max_length=255) cover_api_thumb = EbookField( - 'cover_api_thumb', _('cover thumbnail for API'), + 'cover_api_thumb', _('cover thumbnail for mobile app'), null=True, blank=True, - upload_to=_cover_api_thumb_opload_to, + upload_to=_cover_api_thumb_upload_to, + max_length=255) + simple_cover = EbookField( + 'simple_cover', _('cover for mobile app'), + null=True, blank=True, + upload_to=_simple_cover_upload_to, max_length=255) ebook_formats = constants.EBOOK_FORMATS formats = ebook_formats + ['html', 'xml'] @@ -440,6 +446,7 @@ class Book(models.Model): book.cover.build_delay() book.cover_thumb.build_delay() book.cover_api_thumb.build_delay() + book.simple_cover.build_delay() # Build HTML and ebooks. book.html_file.build_delay() @@ -543,6 +550,7 @@ class Book(models.Model): self.cover.build_delay() self.cover_thumb.build_delay() self.cover_api_thumb.build_delay() + self.simple_cover.build_delay() for format_ in constants.EBOOK_FORMATS_WITH_COVERS: if format_ not in app_settings.DONT_BUILD: getattr(self, '%s_file' % format_).build_delay()