X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/df341bdd09208d2b0f84060454cc0000df19deba..c06d9009a2f0caff4557384179078b4e45edfb8d:/src/cover/views.py diff --git a/src/cover/views.py b/src/cover/views.py index 8a6c93aa..a7b96fbb 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -8,8 +8,8 @@ from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import get_object_or_404, render from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from catalogue.helpers import active_tab -from catalogue.models import Chunk +from documents.helpers import active_tab +from documents.models import Chunk from cover.models import Image from cover import forms @@ -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 @@ -120,8 +133,8 @@ def image_list(request): def add_image(request): form = ff = None if request.method == 'POST': - if request.POST.get('form_id') == 'flickr': - ff = forms.FlickrForm(request.POST) + if request.POST.get('form_id') == 'import': + ff = forms.ImportForm(request.POST) if ff.is_valid(): form = forms.ImageAddForm(ff.cleaned_data) else: @@ -132,7 +145,7 @@ def add_image(request): if form is None: form = forms.ImageAddForm() if ff is None: - ff = forms.FlickrForm() + ff = forms.ImportForm() return render(request, 'cover/add_image.html', { 'form': form, 'ff': ff,