Fixes master
authorRadek Czajka <radekczajka@wolnelektury.pl>
Mon, 16 Nov 2026 07:59:28 +0000 (08:59 +0100)
committerRadek Czajka <radekczajka@wolnelektury.pl>
Mon, 16 Nov 2026 07:59:28 +0000 (08:59 +0100)
requirements/requirements.txt
src/catalogue/models.py
src/cover/forms.py
src/cover/templates/cover/image_detail.html
src/documents/helpers.py
src/documents/views.py
src/redakcja/settings/__init__.py
src/redakcja/settings/defaults.py

index f005eba..0163c6a 100644 (file)
@@ -10,7 +10,7 @@ python-slugify==8.0.1
 python-docx==0.8.11
 Wikidata==0.7
 
-librarian==24.5.9
+librarian==26.11
 
 ## Django
 Django==4.1.9
index 8c3d4cd..84daa46 100644 (file)
@@ -668,6 +668,7 @@ class Thema(models.Model):
 
     @staticmethod
     def standardize(code):
+        if code is None: return None
         return code.split('.')[0]
 
 class Audience(models.Model):
index aad80c4..a1ba182 100644 (file)
@@ -79,14 +79,19 @@ class ImageEditForm(forms.ModelForm):
         model = Image
         exclude = ['download_url', 'use_file', 'example',]
 
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.fields['file'].required = False
+
     def clean(self):
         cleaned_data = super(ImageEditForm, self).clean()
         uploaded_file = cleaned_data.get('file', None)
-        width, height = PILImage.open(uploaded_file.file).size
-        min_width, min_height = settings.MIN_COVER_SIZE
-        if width < min_width or height < min_height:
-            raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') %
-                                        (width, height, min_width, min_height))
+        if uploaded_file is not None:
+            width, height = PILImage.open(uploaded_file.file).size
+            min_width, min_height = settings.MIN_COVER_SIZE
+            if width < min_width or height < min_height:
+                raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') %
+                                            (width, height, min_width, min_height))
 
 
 class ReadonlyImageEditForm(ImageEditForm):
index 6a67eec..64ab3d8 100644 (file)
@@ -32,6 +32,7 @@
 
 
     <div class="col-md-7">
+      {% if object.use_file %}
       {% with perc=object.cut_percentages %}
         <a href="{{ object.use_file.url }}" style="position: relative; display: block; width: {{ perc.width }}px; height: {{ perc.height }}px;">
           {% thumbnail object.file perc.th as th %}
@@ -43,7 +44,8 @@
     <div style="background: black; opacity: .5; display: block; position: absolute; top: {{ perc.top }}%; bottom: {{ perc.bottom }}%; left: 0; width: {{ perc.left }}%"></div>
     <div style="background: black; opacity: .5; display: block; position: absolute; top: {{ perc.top }}%; bottom: {{ perc.bottom }}%; right: 0; width: {{ perc.right }}%"></div>
       {% endlocalize %}
-      {% endwith %}
+    {% endwith %}
+    {% endif %}
         </a>
         <br/><a href="{{ object.source_url }}">{{ object.title }}</a> by {{ object.author }},
         {% if object.license_url %}<a href="{{ object.license_url }}">{% endif %}
     </div>
   </div>
 
-
+{% if object.use_file %}
   <textarea style="width:100%" rows="6" class="form-control mt-4" disabled>
 &lt;dc:relation.coverImage.url xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.use_file.url|build_absolute_uri:request }}&lt;/dc:relation.coverImage.url>
 &lt;dc:relation.coverImage.attribution xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.attribution }}&lt;/dc:relation.coverImage.attribution>
 &lt;dc:relation.coverImage.source xmlns:dc="http://purl.org/dc/elements/1.1/">{{ object.get_full_url }}&lt;/dc:relation.coverImage.source></textarea>
+  {% endif %}
 
   <div class="card mt-4">
     <div class="card-header">
index df15b91..8617d23 100644 (file)
@@ -3,7 +3,7 @@
 #
 from datetime import date
 from functools import wraps
-from os.path import join
+from os.path import join, exists
 from os import listdir, stat
 from shutil import move, rmtree
 from django.conf import settings
@@ -77,9 +77,9 @@ class GalleryMerger(object):
         return self.dest_size is not None
 
     def merge(self):
-        if not self.dest:
+        if not self.dest or not exists(self.path(self.dest)):
             return self.src
-        if not self.src:
+        if not self.src or not exists(self.path(self.src)):
             return self.dest
 
         files = listdir(self.path(self.dest))
index cab58be..1fe7b05 100644 (file)
@@ -264,7 +264,11 @@ def book_html(request, slug):
         return HttpResponseForbidden("Not authorized.")
 
     doc = book.wldocument(parse_dublincore=False)
-    html = doc.as_html(options={'gallery': "'%s'" % book.gallery_url()})
+    html = doc.as_html(
+        gallery_url='%stmp/html/' % settings.MEDIA_URL,
+        gallery_path='%s/tmp/html/' % settings.MEDIA_ROOT,
+        base_url=request.build_absolute_uri(book.gallery_url()),
+        options={'gallery': "'%s'" % book.gallery_url()})
 
     html = html.get_bytes().decode('utf-8') if html is not None else ''
     # response = http.HttpResponse(html, content_type='text/html')
@@ -290,7 +294,7 @@ def book_pdf(request, slug, mobile=False):
     doc = book.wldocument()
     # TODO: error handling
     customizations = ['26pt', 'nothemes', 'nomargins', 'notoc'] if mobile else None
-    pdf_file = doc.as_pdf(cover=True, base_url=request.build_absolute_uri(book.gallery_path()), customizations=customizations)
+    pdf_file = doc.as_pdf(cover=True, base_url=request.build_absolute_uri(book.gallery_url()), customizations=customizations)
     from .ebook_utils import serve_file
     return serve_file(pdf_file.get_filename(),
                 book.slug + '.pdf', 'application/pdf')
@@ -414,9 +418,14 @@ def book(request, slug):
 
     cbook_by_slug = None
     if book.dc_slug:
-        audio_items = requests.get(f'https://audio.wolnelektury.pl/archive/book/{book.dc_slug}.json').json()['items']
-        has_audio = bool(audio_items)
-        can_sell_audio = has_audio and all(x['project']['can_sell'] for x in audio_items)
+        try:
+            audio_items = requests.get(f'https://audio.wolnelektury.pl/archive/book/{book.dc_slug}.json').json()['items']
+        except:
+            has_audio = None
+            can_sell_audio = None
+        else:
+            has_audio = bool(audio_items)
+            can_sell_audio = has_audio and all(x['project']['can_sell'] for x in audio_items)
 
         if book.catalogue_book is None or book.dc_slug != book.catalogue_book.slug:
             cbook_by_slug = catalogue.models.Book.objects.filter(slug=book.dc_slug).first()
index f238349..3eed3e4 100644 (file)
@@ -135,8 +135,6 @@ LOCALE_PATHS = [
 
 LOGIN_REDIRECT_URL = '/documents/user'
 
-MIN_COVER_SIZE = (915, 1270)
-
 LEGIMI_SMALL_WORDS = 2000
 LEGIMI_BIG_WORDS = 10000
 LEGIMI_SMALL_PRICE = 7
index 297cd42..db07037 100644 (file)
@@ -78,3 +78,4 @@ LEGIMI_USERNAME = None
 LEGIMI_PASSWORD = None
 LEGIMI_PUBLISHER_ID = None
 
+MIN_COVER_SIZE = (800, 800)