X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/4cab8b0725fd5a88f5a508e584b4acd346a824fc..11135898543370ecf4ffa95dbea14cba4c33f57c:/src/cover/views.py?ds=sidebyside diff --git a/src/cover/views.py b/src/cover/views.py index d00123cc..302f5f52 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -7,7 +7,7 @@ import os.path import PIL.Image from django.conf import settings from django.contrib.auth.decorators import permission_required -from django.http import HttpResponse, HttpResponseRedirect, Http404 +from django.http import HttpResponse, HttpResponseRedirect, Http404, JsonResponse 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 @@ -65,7 +65,11 @@ def preview(request, book, chunk=None, rev=None): cover_class = request.GET.get('cover_class', 'default') - cover = make_cover(info, cover_class=cover_class, width=width, height=height) + kwargs = {} + if chunk.book.project is not None: + if chunk.book.project.logo_mono or chunk.book.project.logo: + kwargs['cover_logo'] = (chunk.book.project.logo_mono or chunk.book.project.logo).path + cover = make_cover(info, cover_class=cover_class, width=width, height=height, **kwargs) response = HttpResponse(content_type=cover.mime_type()) img = cover.final_image() img.save(response, cover.format) @@ -103,6 +107,22 @@ def preview_from_xml(request): def image(request, pk): img = get_object_or_404(Image, pk=pk) + if not request.accepts('text/html') and request.accepts('application/json') or request.GET.get('format') == 'json': + return JsonResponse({ + 'title': img.title, + 'author': img.author, + 'license_name': img.license_name, + 'license_url': img.license_url, + 'source_url': img.source_url, + 'attribution': img.attribution, + 'cut_left': img.cut_left, + 'cut_right': img.cut_right, + 'cut_top': img.cut_top, + 'cut_bottom': img.cut_bottom, + 'file': img.file.url, + 'use_file': img.use_file.url, + }) + if request.user.has_perm('cover.change_image'): if request.method == "POST": form = forms.ImageEditForm(request.POST, request.FILES, instance=img) @@ -130,9 +150,14 @@ def image_file(request, pk): @active_tab('cover') def image_list(request): + qs = Image.objects.all().order_by('-id') + only_unused = request.GET.get('unused') + if only_unused: + qs = qs.filter(book=None) return render(request, "cover/image_list.html", { - 'object_list': Image.objects.all().order_by('-id'), + 'object_list': qs, 'can_add': request.user.has_perm('cover.add_image'), + 'only_unused': only_unused, })