From: Radek Czajka Date: Wed, 7 Feb 2024 11:10:37 +0000 (+0100) Subject: Bit nicer source flow. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/049c5959e33d29e4c0044c235d291144d49d3c45 Bit nicer source flow. --- diff --git a/src/catalogue/templates/catalogue/book_detail.html b/src/catalogue/templates/catalogue/book_detail.html index 3c98787c..37cbb662 100644 --- a/src/catalogue/templates/catalogue/book_detail.html +++ b/src/catalogue/templates/catalogue/book_detail.html @@ -125,14 +125,39 @@ {{ bs.source }} {% if bs.page_start or bs.page_end %} - ({{ bs.page_start }}—{{ bs.page_end }}) + (strony {{ bs.page_start }}—{{ bs.page_end }}) {% else %} - (całość) + + (źródło w całości przypisane do utworu {{ book }}) + + {% endif %} + + {% if not bs.source.has_upload_files %} + +
+ Źródło nie ma jeszcze załadowanych skanów. + + Załaduj skany. +
+ + {% elif not bs.source.has_view_files %} +
+ Trwa generowanie podglądu. +
+ {% elif not bs.source.has_ocr_files %} +
+ Trwa OCR. +
+ {% elif bs.source.modified_at > bs.source.processed_at %} +
+ Zmodyfikowano skany, trwa aktualizacja. +
+ {% else %} +
+ {% csrf_token %} + +
{% endif %} -
- {% csrf_token %} - -
{% empty %} Brak źródła. Możesz je dodać. diff --git a/src/fileupload/templates/fileupload/picture_form.html b/src/fileupload/templates/fileupload/picture_form.html index dc49f9c9..0bc6ae81 100644 --- a/src/fileupload/templates/fileupload/picture_form.html +++ b/src/fileupload/templates/fileupload/picture_form.html @@ -26,6 +26,7 @@ {% endfor %} +{% block note %}{% endblock %}
{% csrf_token %}
diff --git a/src/sources/management/commands/sources_process.py b/src/sources/management/commands/sources_process.py new file mode 100644 index 00000000..8b3efa91 --- /dev/null +++ b/src/sources/management/commands/sources_process.py @@ -0,0 +1,17 @@ +from django.core.management.base import BaseCommand +from django.db.models import F +from sources.models import Source + + +class Command(BaseCommand): + def handle(self, **options): + for s in Source.objects.exclude( + modified_at=None + ).exclude(processed_at__gt=F('modified_at')).order_by('modified_at'): + print(s) + try: + s.process() + except Exception as e: + print(e) + pass + diff --git a/src/sources/models.py b/src/sources/models.py index 0b55c890..165cb67b 100644 --- a/src/sources/models.py +++ b/src/sources/models.py @@ -38,6 +38,10 @@ class Source(models.Model): def get_ocr_directory(self): return f'sources/ocr/{self.pk}/' + def has_upload_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_upload_directory()) + return os.path.isdir(d) and os.listdir(d) + def get_view_files(self): d = self.get_view_directory() return [ @@ -47,6 +51,10 @@ class Source(models.Model): )) ] + def has_view_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_view_directory()) + return os.path.isdir(d) and os.listdir(d) + def get_ocr_files(self): d = os.path.join(settings.MEDIA_ROOT, self.get_ocr_directory()) return [ @@ -54,6 +62,10 @@ class Source(models.Model): for name in sorted(os.listdir(d)) ] + def has_ocr_files(self): + d = os.path.join(settings.MEDIA_ROOT, self.get_ocr_directory()) + return os.path.isdir(d) and os.listdir(d) + def process(self): updir = os.path.join( settings.MEDIA_ROOT, diff --git a/src/sources/templates/sources/source_detail.html b/src/sources/templates/sources/source_detail.html index 240a2b35..30faa6ee 100644 --- a/src/sources/templates/sources/source_detail.html +++ b/src/sources/templates/sources/source_detail.html @@ -2,7 +2,7 @@ {% load sorl_thumbnail %} {% block content %} -

{{ source }}

+

Źródło: {{ source }}

@@ -13,9 +13,16 @@

Przypisania do książek:

{% for bs in source.booksource_set.all %}
- - {{ bs.book }} {{ bs.page_start }}—{{ bs.page_end }} + + {{ bs.book }} + + {% if bs.page_start or bs.page_end %} + (skany {{ bs.page_start }}—{{ bs.page_end }}) + {% else %} + (całość) + {% endif %} +
{% for f in bs.get_files %} {% thumbnail f '200x200' as c %} diff --git a/src/sources/templates/sources/upload.html b/src/sources/templates/sources/upload.html new file mode 100644 index 00000000..39e64066 --- /dev/null +++ b/src/sources/templates/sources/upload.html @@ -0,0 +1,7 @@ +{% extends 'fileupload/picture_form.html' %} + +{% block note %} +
+ Skany źródła ładujemy w oryginalnej jakości. +
+{% endblock %} diff --git a/src/sources/views.py b/src/sources/views.py index a5664f77..2faaecea 100644 --- a/src/sources/views.py +++ b/src/sources/views.py @@ -12,6 +12,8 @@ class SourceView(DetailView): class SourceUploadView(UploadView): + template_name = 'sources/upload.html' + def get_object(self, request, sid): source = get_object_or_404(models.Source, id=sid) return source