From: Radek Czajka Date: Tue, 5 Dec 2023 14:08:34 +0000 (+0100) Subject: Epub debugging. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/fbb8f42993d02108b506028dc85466a0541be359 Epub debugging. --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 7dcf4fde..8feffa88 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -10,7 +10,7 @@ python-slugify==8.0.1 python-docx==0.8.11 Wikidata==0.7 -librarian==23.08 +librarian==23.12 ## Django Django==4.1.9 diff --git a/src/depot/publishers/base.py b/src/depot/publishers/base.py index 88ee56b2..8fff399c 100644 --- a/src/depot/publishers/base.py +++ b/src/depot/publishers/base.py @@ -44,10 +44,11 @@ class BasePublisher: ) if p is not None else '' for p in wlbook.meta.authors ) + '
' - description += '{}
'.format( - wlbook.meta.url.slug, - wlbook.meta.title - ) + if wlbook.meta.url is not None: + description += '{}
'.format( + wlbook.meta.url.slug, + wlbook.meta.title + ) if wlbook.meta.translators: description += 'tłum. ' + ', '.join(p.readable() for p in wlbook.meta.translators) + '
' description += 'Epoka: ' + ', '.join( diff --git a/src/documents/templates/documents/book_detail.html b/src/documents/templates/documents/book_detail.html index a286302f..2d587349 100644 --- a/src/documents/templates/documents/book_detail.html +++ b/src/documents/templates/documents/book_detail.html @@ -122,7 +122,8 @@ {% trans "TXT version" %}
{% trans "PDF version" %}
{% trans "PDF version for mobiles" %}
- {% trans "EPUB version" %}
+ {% trans "EPUB version" %} + sprawdź
{% trans "MOBI version" %}

diff --git a/src/documents/templates/documents/book_epubcheck.html b/src/documents/templates/documents/book_epubcheck.html new file mode 100644 index 00000000..ca0a0f94 --- /dev/null +++ b/src/documents/templates/documents/book_epubcheck.html @@ -0,0 +1,43 @@ +{% extends "documents/base.html" %} +{% load book_list i18n %} +{% load bootstrap4 %} +{% load depot %} +{% load isbn %} + + +{% block titleextra %}{{ book.title }}{% endblock %} + + +{% block content %} + +
+
+

Weryfikacja epub: {{ book.title }}

+
+
+ {% for msg in messages %} +
+ {{ msg.message }} + {% if msg.suggestion %} +

+ {{ msg.suggestion }} + {% endif %} + {% for loc in msg.locations %} + {% if loc.wl_chunk %} +
+ + {% if loc.wl_chunk.title %} + {{ loc.wl_chunk.title }}: + {% endif %} + Linia {{ loc.wl_line }} + + {% else %} +
{{ loc }} + {% endif %} + {% endfor %} +
+ {% endfor %} +
+
+ +{% endblock content %} diff --git a/src/documents/urls.py b/src/documents/urls.py index 71ce10a0..d9114cc1 100644 --- a/src/documents/urls.py +++ b/src/documents/urls.py @@ -41,6 +41,7 @@ urlpatterns = [ path('book//txt', views.book_txt, name="documents_book_txt"), path('book//html', views.book_html, name="documents_book_html"), path('book//epub', views.book_epub, name="documents_book_epub"), + path('book//epubcheck', views.book_epubcheck, name="documents_book_epubcheck"), path('book//mobi', views.book_mobi, name="documents_book_mobi"), path('book//pdf', views.book_pdf, name="documents_book_pdf"), path('book//pdf-mobile', views.book_pdf, kwargs={'mobile': True}, name="documents_book_pdf_mobile"), diff --git a/src/documents/views.py b/src/documents/views.py index ecc92199..905e885b 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -23,6 +23,7 @@ from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_POST from django_cas_ng.decorators import user_passes_test +from librarian import epubcheck from apiclient import api_call, NotAuthorizedError from . import forms from . import helpers @@ -300,7 +301,8 @@ def book_epub(request, slug): from librarian.builders import EpubBuilder epub = EpubBuilder( - base_url='file://' + book.gallery_path() + '/' + base_url='file://' + book.gallery_path() + '/', + debug=True ).build(doc).get_bytes() response = HttpResponse(content_type='application/epub+zip') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub' @@ -308,6 +310,35 @@ def book_epub(request, slug): return response +@login_required +@never_cache +def book_epubcheck(request, slug): + book = get_object_or_404(Book, slug=slug) + if not book.accessible(request): + return HttpResponseForbidden("Not authorized.") + + # TODO: move to celery + doc = book.wldocument(librarian2=True) + # TODO: error handling + + from librarian.builders import EpubBuilder + epub = EpubBuilder( + base_url='file://' + book.gallery_path() + '/', + debug=True + ).build(doc) + fname = epub.get_filename() + + messages = epubcheck.epubcheck(fname) + for message in messages: + for location in message.get('locations', []): + if 'wl_chunk' in location: + location['wl_chunk'] = book[location['wl_chunk']] + return render(request, 'documents/book_epubcheck.html', { + 'messages': messages, + 'book': book, + }) + + @login_required @never_cache def book_mobi(request, slug): diff --git a/src/documents/xml_tools.py b/src/documents/xml_tools.py index f2c885d9..ac145db4 100644 --- a/src/documents/xml_tools.py +++ b/src/documents/xml_tools.py @@ -21,7 +21,11 @@ def _trim(text, trim_begin=True, trim_end=True): that eg. one big XML file can be compiled from many small XML files. """ if trim_begin: - text = RE_TRIM_BEGIN.split(text, maxsplit=1)[-1] + parts = RE_TRIM_BEGIN.split(text, maxsplit=1) + text = parts[-1] + if len(parts) > 1: + lines = parts[0].count('\n') + text = f'' + text if trim_end: text = RE_TRIM_END.split(text, maxsplit=1)[0] return text diff --git a/src/sources/document.py b/src/sources/document.py index e46ce2f5..876bda9b 100644 --- a/src/sources/document.py +++ b/src/sources/document.py @@ -48,7 +48,7 @@ def add_rdf(root, book_source): # created_at etree.SubElement(desc, DCNS('date')).text = date.today().isoformat() # date.pd - etree.SubElement(desc, DCNS('date.pd')).text = book.pd_year + etree.SubElement(desc, DCNS('date.pd')).text = str(book.pd_year) #publisher etree.SubElement(desc, DCNS('publisher')). text = 'Fundacja Wolne Lektury' #language