{{ 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 %}
- (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 %}
- <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ć.
{% endfor %}
</h1>
+{% block note %}{% endblock %}
<form id="fileupload" method="post" action="." enctype="multipart/form-data">{% csrf_token %}
<div class="row fileupload-buttonbar">
--- /dev/null
+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
+
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 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 [
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,
{% load sorl_thumbnail %}
{% block content %}
- <h1>{{ source }}</h1>
+ <h1>Źródło: {{ source }}</h1>
<p>
<a href="{% url 'source_upload' source.pk %}">
<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>
+ <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 %}
--- /dev/null
+{% extends 'fileupload/picture_form.html' %}
+
+{% block note %}
+ <div class="alert alert-info">
+ Skany źródła ładujemy w oryginalnej jakości.
+ </div>
+{% endblock %}
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