Bit nicer source flow.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 7 Feb 2024 11:10:37 +0000 (12:10 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 7 Feb 2024 11:10:37 +0000 (12:10 +0100)
src/catalogue/templates/catalogue/book_detail.html
src/fileupload/templates/fileupload/picture_form.html
src/sources/management/commands/sources_process.py [new file with mode: 0644]
src/sources/models.py
src/sources/templates/sources/source_detail.html
src/sources/templates/sources/upload.html [new file with mode: 0644]
src/sources/views.py

index 3c98787..37cbb66 100644 (file)
           {{ bs.source }}
         </a>
         {% if bs.page_start or bs.page_end %}
           {{ bs.source }}
         </a>
         {% if bs.page_start or bs.page_end %}
-          ({{ bs.page_start }}—{{ bs.page_end }})
+          (strony {{ bs.page_start }}—{{ bs.page_end }})
         {% else %}
         {% else %}
-          (całość)
+          <small>
+            (źródło w całości przypisane do utworu <em>{{ book }}</em>)
+          </small>
+        {% endif %}
+
+        {% if not bs.source.has_upload_files %}
+
+          <div class="alert alert-info">
+            Źródło nie ma jeszcze załadowanych skanów.
+            <a href="{% url 'source_upload' bs.source.id %}">
+              Załaduj skany</a>.
+          </div>
+
+        {% elif not bs.source.has_view_files %}
+          <div class="alert alert-info">
+            Trwa generowanie podglądu.
+          </div>
+        {% elif not bs.source.has_ocr_files %}
+          <div class="alert alert-info">
+            Trwa OCR.
+          </div>
+        {% elif bs.source.modified_at > bs.source.processed_at %}
+          <div class="alert alert-info">
+            Zmodyfikowano skany, trwa aktualizacja.
+          </div>
+        {% else %}
+          <form method="post" action="{% url 'source_book_prepare' bs.pk %}">
+            {% csrf_token %}
+            <button class="btn btn-primary">Utwórz tekst książki</button>
+          </form>
         {% endif %}
         {% endif %}
-        <form method="post" action="{% url 'source_book_prepare' bs.pk %}">
-          {% csrf_token %}
-          <button class="btn btn-primary">Utwórz tekst książki</button>
-        </form>
       {% empty %}
         Brak źródła.
         Możesz je dodać.
       {% empty %}
         Brak źródła.
         Możesz je dodać.
index dc49f9c..0bc6ae8 100644 (file)
@@ -26,6 +26,7 @@
 {% endfor %}
 </h1>
 
 {% endfor %}
 </h1>
 
+{% block note %}{% endblock %}
 
     <form id="fileupload" method="post" action="." enctype="multipart/form-data">{% csrf_token %}
         <div class="row fileupload-buttonbar">
 
     <form id="fileupload" method="post" action="." enctype="multipart/form-data">{% csrf_token %}
         <div class="row fileupload-buttonbar">
diff --git a/src/sources/management/commands/sources_process.py b/src/sources/management/commands/sources_process.py
new file mode 100644 (file)
index 0000000..8b3efa9
--- /dev/null
@@ -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
+
index 0b55c89..165cb67 100644 (file)
@@ -38,6 +38,10 @@ class Source(models.Model):
     def get_ocr_directory(self):
         return f'sources/ocr/{self.pk}/'
 
     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 [
     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 [
     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))
         ]
 
             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,
     def process(self):
         updir = os.path.join(
             settings.MEDIA_ROOT,
index 240a2b3..30faa6e 100644 (file)
@@ -2,7 +2,7 @@
 {% load sorl_thumbnail %}
 
 {% block content %}
 {% load sorl_thumbnail %}
 
 {% block content %}
-  <h1>{{ source }}</h1>
+  <h1>Źródło: {{ source }}</h1>
 
   <p>
   <a href="{% url 'source_upload' source.pk %}">
 
   <p>
   <a href="{% url 'source_upload' source.pk %}">
   <h2>Przypisania do książek:</h2>
   {% for bs in source.booksource_set.all %}
     <div>
   <h2>Przypisania do książek:</h2>
   {% for bs in source.booksource_set.all %}
     <div>
-      <a href="{% url 'source_book_prepare' bs.pk %}">
-        {{ bs.book }} {{ bs.page_start }}—{{ bs.page_end }}
+      <a href="{{ bs.book.get_absolute_url }}">
+        {{ bs.book }}
       </a>
       </a>
+      <small>
+        {% if bs.page_start or bs.page_end %}
+          (skany {{ bs.page_start }}—{{ bs.page_end }})
+        {% else %}
+          (całość)
+        {% endif %}
+      </small>
     </div>
     {% for f in bs.get_files %}
       {% thumbnail f '200x200' as c %}
     </div>
     {% 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 (file)
index 0000000..39e6406
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends 'fileupload/picture_form.html' %}
+
+{% block note %}
+  <div class="alert alert-info">
+    Skany źródła ładujemy w oryginalnej jakości.
+  </div>
+{% endblock %}
index a5664f7..2faaece 100644 (file)
@@ -12,6 +12,8 @@ class SourceView(DetailView):
 
 
 class SourceUploadView(UploadView):
 
 
 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
     def get_object(self, request, sid):
         source = get_object_or_404(models.Source, id=sid)
         return source