From: Radek Czajka Date: Mon, 16 Nov 2026 07:59:28 +0000 (+0100) Subject: Fixes X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/ac5de8695878cb6aabf9161930af189cf5d15316 Fixes --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index f005eba9..0163c6af 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==24.5.9 +librarian==26.11 ## Django Django==4.1.9 diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 8c3d4cdf..84daa469 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -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): diff --git a/src/cover/forms.py b/src/cover/forms.py index aad80c4d..a1ba182d 100644 --- a/src/cover/forms.py +++ b/src/cover/forms.py @@ -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): diff --git a/src/cover/templates/cover/image_detail.html b/src/cover/templates/cover/image_detail.html index 6a67eecc..64ab3d81 100644 --- a/src/cover/templates/cover/image_detail.html +++ b/src/cover/templates/cover/image_detail.html @@ -32,6 +32,7 @@
+ {% if object.use_file %} {% with perc=object.cut_percentages %} {% thumbnail object.file perc.th as th %} @@ -43,7 +44,8 @@
{% endlocalize %} - {% endwith %} + {% endwith %} + {% endif %}

{{ object.title }} by {{ object.author }}, {% if object.license_url %}{% endif %} @@ -58,11 +60,12 @@
- +{% if object.use_file %} + {% endif %}
diff --git a/src/documents/helpers.py b/src/documents/helpers.py index df15b91d..8617d234 100644 --- a/src/documents/helpers.py +++ b/src/documents/helpers.py @@ -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)) diff --git a/src/documents/views.py b/src/documents/views.py index cab58bee..1fe7b054 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -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() diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index f2383498..3eed3e45 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -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 diff --git a/src/redakcja/settings/defaults.py b/src/redakcja/settings/defaults.py index 297cd422..db07037d 100644 --- a/src/redakcja/settings/defaults.py +++ b/src/redakcja/settings/defaults.py @@ -78,3 +78,4 @@ LEGIMI_USERNAME = None LEGIMI_PASSWORD = None LEGIMI_PUBLISHER_ID = None +MIN_COVER_SIZE = (800, 800)