From: Jan Szejko Date: Fri, 9 Dec 2016 15:05:27 +0000 (+0100) Subject: epub covers X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/1be8522e57289f6eafdb8c1bf73532b2c0f4e3e0?ds=inline;hp=9c9d869e6252d1af4e4747fdfe0d0d7a4ede3d19 epub covers --- diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index 72ed9cb9..d116fcb1 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -13,12 +13,14 @@ from django.db.models import Count from django import http from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect +from django.utils.encoding import force_str from django.utils.http import urlquote_plus from django.views.decorators.http import require_POST from catalogue import forms from catalogue import helpers from catalogue.helpers import active_tab +from librarian import BuildError from .constants import STAGES from .models import Document, Plan from dvcs.models import Revision @@ -353,7 +355,11 @@ def book_epub(request, pk, rev_pk): ) if doc.owner_organization is not None and doc.owner_organization.logo: ctx.cover_logo = 'http://%s%s' % (request.get_host(), doc.owner_organization.logo.url) - epub_file = EpubFormat(sst).build(ctx) + try: + epub_file = EpubFormat(sst).build(ctx) + except BuildError as e: + from django.http import HttpResponse + return HttpResponse(content=force_str(e.message), content_type='text/plain', status='400') from catalogue.ebook_utils import serve_file return serve_file(epub_file.get_filename(), '%d.epub' % doc.pk, 'application/epub+zip')