From: Radek Czajka Date: Sun, 22 Mar 2020 09:37:51 +0000 (+0100) Subject: Cover download button. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/ad2f309daa381e9a7a2b7a8a17ef494b60f838b2?ds=inline;hp=-c Cover download button. --- ad2f309daa381e9a7a2b7a8a17ef494b60f838b2 diff --git a/src/catalogue/templates/catalogue/book_detail.html b/src/catalogue/templates/catalogue/book_detail.html index 800bf228..b625b7e7 100644 --- a/src/catalogue/templates/catalogue/book_detail.html +++ b/src/catalogue/templates/catalogue/book_detail.html @@ -64,6 +64,13 @@ {% if book.dc_cover_image %} {{ book.dc_cover_image }} {% endif %} +

+
+ +Okładka w rozmiarze + x + +

{% trans "Last published" %}: diff --git a/src/cover/views.py b/src/cover/views.py index 8a6c93aa..b1261e6d 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -42,10 +42,23 @@ def preview(request, book, chunk=None, rev=None): info = BookInfo.from_bytes(xml) except: return HttpResponseRedirect(os.path.join(settings.STATIC_URL, "img/sample_cover.png")) - cover = make_cover(info) + width = request.GET.get('width') + width = int(width) if width else None + height=request.GET.get('height') + height = int(height) if height else None + cover = make_cover(info, width=width, height=height) + #cover = make_cover(info) response = HttpResponse(content_type=cover.mime_type()) - img = cover.image().resize(PREVIEW_SIZE, Image.ANTIALIAS) + if height or width: + size = (width, height) + else: + size = PREVIEW_SIZE + img = cover.image().resize(size, Image.ANTIALIAS) img.save(response, cover.format) + + if 'download' in request.GET: + response['Content-Disposition'] = 'attachment; filename=%s.jpg' % chunk.book.slug + return response