Cover download button.
authorRadek Czajka <rczajka@rczajka.pl>
Sun, 22 Mar 2020 09:37:51 +0000 (10:37 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Sun, 22 Mar 2020 09:37:51 +0000 (10:37 +0100)
src/catalogue/templates/catalogue/book_detail.html
src/cover/views.py

index 800bf22..b625b7e 100644 (file)
 {% if book.dc_cover_image %}
     <a href="{{ book.dc_cover_image.get_absolute_url }}">{{ book.dc_cover_image }}</a>
 {% endif %}
 {% if book.dc_cover_image %}
     <a href="{{ book.dc_cover_image.get_absolute_url }}">{{ book.dc_cover_image }}</a>
 {% endif %}
+<br><br>
+<form action="{% url 'cover_preview' book.slug %}">
+<input type="hidden" name="download" value="1">
+OkÅ‚adka w rozmiarze
+<input name="width" type="number" required value="600"> x <input name="height" type="number" required value="833">
+<button type="submit" class="btn btn-sm btn-primary">Pobierz</button>
+</form>
 </div>
 <div class="col-lg-9">
 <p>{% trans "Last published" %}: 
 </div>
 <div class="col-lg-9">
 <p>{% trans "Last published" %}: 
index 8a6c93a..b1261e6 100644 (file)
@@ -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"))
         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())
     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)
     img.save(response, cover.format)
+
+    if 'download' in request.GET:
+        response['Content-Disposition'] = 'attachment; filename=%s.jpg' % chunk.book.slug
+
     return response
 
 
     return response