From 14ccdb3747519e378f69d2f64f5a041a6dd5391c Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 9 Nov 2026 14:08:41 +0100 Subject: [PATCH 01/16] Replace libsass with dart-sass. --- Dockerfile | 5 +++++ requirements/requirements.txt | 1 - src/wolnelektury/settings/static.py | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 08ec72375..424f37bef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,11 @@ RUN apt-get update && apt-get install -y \ texlive-fonts-extra-links \ fonts-noto-core fonts-noto-extra +# Install dart-sass for compiling SCSS. +ARG DART_SASS_VERSION=1.108.1 +RUN arch=$(dpkg --print-architecture | sed 's/amd64/x64/') && \ + curl -fsSL "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-${arch}.tar.gz" \ + | tar xz -C /opt COPY requirements/requirements.txt requirements.txt diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 0ec90837a..e60b7b0ab 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -8,7 +8,6 @@ docutils==0.23 pymemcache==4.0.0 django-pipeline==3.1.0 -libsasscompiler==0.2.1 jsmin==3.0.1 fnp-django-pagination==2.2.12 diff --git a/src/wolnelektury/settings/static.py b/src/wolnelektury/settings/static.py index b83691b24..9c2960fbd 100644 --- a/src/wolnelektury/settings/static.py +++ b/src/wolnelektury/settings/static.py @@ -134,18 +134,18 @@ PIPELINE = { 'output_filename': 'js/widget.min.js', }, }, - 'CSS_COMPRESSOR': None, 'JS_COMPRESSOR': 'pipeline.compressors.jsmin.JSMinCompressor', - 'COMPILERS': ( - 'libsasscompiler.LibSassCompiler', - ) + 'COMPILERS': ('pipeline.compilers.sass.SASSCompiler',), + 'SASS_BINARY': '/opt/dart-sass/sass', + 'SASS_ARGUMENTS': '--embed-source-map --embed-sources', + # Compress CSSwith a second run of dart-sass. + 'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor', + 'CSSMIN_BINARY': '/opt/dart-sass/sass', + 'CSSMIN_ARGUMENTS': '--stdin --style=compressed --no-source-map', } STATICFILES_STORAGE = 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage' -# PIPELINE_PYSCSS_BINARY = '/usr/bin/env pyscss' -# PIPELINE_PYSCSS_ARGUMENTS = '' - STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', -- 2.20.1 From 6d7faa17f8ba5a94528372f246b2e774dc533a10 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 9 Nov 2026 14:14:04 +0100 Subject: [PATCH 02/16] upgrade pipeline --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index e60b7b0ab..4e9120b9c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -7,7 +7,7 @@ docutils==0.23 pymemcache==4.0.0 -django-pipeline==3.1.0 +django-pipeline==4.1.0 jsmin==3.0.1 fnp-django-pagination==2.2.12 -- 2.20.1 From 00816a95ccf017eee4d78953edfae38fc7ab47c1 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 9 Nov 2026 15:21:30 +0100 Subject: [PATCH 03/16] Upgrade for allauth --- requirements/requirements.txt | 2 +- src/wolnelektury/settings/auth.py | 19 ------------------- src/wolnelektury/settings/basic.py | 1 + .../{account => allauth/layouts}/base.html | 0 4 files changed, 2 insertions(+), 20 deletions(-) rename src/wolnelektury/templates/{account => allauth/layouts}/base.html (100%) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4e9120b9c..ae4c24885 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -12,7 +12,7 @@ jsmin==3.0.1 fnp-django-pagination==2.2.12 django-modeltranslation==0.18.12 -django-allauth==0.54 +django-allauth[socialaccount,openid]==0.63.6 django-extensions==3.2.3 djangorestframework==3.15.1 django-filter==23.5 diff --git a/src/wolnelektury/settings/auth.py b/src/wolnelektury/settings/auth.py index 89e520f46..2fe844c6e 100644 --- a/src/wolnelektury/settings/auth.py +++ b/src/wolnelektury/settings/auth.py @@ -29,24 +29,5 @@ SOCIALACCOUNT_PROVIDERS = { 'facebook': { 'METHOD': 'oauth2', 'SCOPE': ['email', 'public_profile'], - # 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, - # 'INIT_PARAMS': {'cookie': True}, - # 'FIELDS': [ - # 'id', - # 'email', - # 'name', - # 'first_name', - # 'last_name', - # 'verified', - # 'locale', - # 'timezone', - # 'link', - # 'gender', - # 'updated_time', - # ], - # 'EXCHANGE_TOKEN': True, - # 'LOCALE_FUNC': 'path.to.callable', - # 'VERIFIED_EMAIL': False, - 'VERSION': 'v2.12', }, } diff --git a/src/wolnelektury/settings/basic.py b/src/wolnelektury/settings/basic.py index fe048e4bb..1b86642e3 100644 --- a/src/wolnelektury/settings/basic.py +++ b/src/wolnelektury/settings/basic.py @@ -118,6 +118,7 @@ MIDDLEWARE = [ 'fnpdjango.middleware.SetRemoteAddrFromXRealIP', 'django.middleware.cache.FetchFromCacheMiddleware', 'experiments.middleware.experiments_middleware', + "allauth.account.middleware.AccountMiddleware", ] ROOT_URLCONF = 'wolnelektury.urls' diff --git a/src/wolnelektury/templates/account/base.html b/src/wolnelektury/templates/allauth/layouts/base.html similarity index 100% rename from src/wolnelektury/templates/account/base.html rename to src/wolnelektury/templates/allauth/layouts/base.html -- 2.20.1 From 9a92f29fcf613eb9aac02d636376d1f6a4a6d243 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 9 Nov 2026 16:43:08 +0100 Subject: [PATCH 04/16] Allow temp dirs during pipeline --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 424f37bef..f6debff91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -97,6 +97,11 @@ COPY src /app/src # FROM app AS static-builder +# django-pipeline compiler creates temp dirs in place. Let it. +USER root +RUN find /app/src/*/static -type d -exec chown app {} + +USER app + RUN python manage.py collectstatic --noinput -- 2.20.1 From cf8293721af2c9c13a627198d38ea90a8449fdec Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 9 Nov 2026 17:16:00 +0100 Subject: [PATCH 05/16] Upgrade Django --- requirements/requirements-dev.txt | 2 +- requirements/requirements.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index 9be0df967..5b58a1fe5 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -1,6 +1,6 @@ -i https://py.mdrn.pl/simple/ -django-debug-toolbar==3.2.2 +django-debug-toolbar django-debug-toolbar-template-timings sphinx pyinotify diff --git a/requirements/requirements.txt b/requirements/requirements.txt index ae4c24885..9c3aa7959 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,8 +1,8 @@ -i https://py.mdrn.pl/simple/ # django -Django==4.0.8 -fnpdjango==0.6 +Django==4.2.30 +fnpdjango==0.7 docutils==0.23 pymemcache==4.0.0 -- 2.20.1 From b09ddc60e118508d96906f26ecb0e1709ca89f1b Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 00:10:49 +0100 Subject: [PATCH 06/16] For upgrades --- .../0004_bookuserdata_last_changed.py | 3 +-- src/bookmarks/models.py | 20 ++++++++----------- src/club/models.py | 8 ++++---- src/funding/models.py | 8 ++++---- src/lesmianator/models.py | 4 ++-- src/social/api/views.py | 6 +++--- src/social/models.py | 2 +- src/social/syncable.py | 6 +++--- src/wolnelektury/settings/locale.py | 1 - 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/api/migrations/0004_bookuserdata_last_changed.py b/src/api/migrations/0004_bookuserdata_last_changed.py index 1e6f04715..fe6f9400d 100644 --- a/src/api/migrations/0004_bookuserdata_last_changed.py +++ b/src/api/migrations/0004_bookuserdata_last_changed.py @@ -3,7 +3,6 @@ # import datetime from django.db import migrations, models -from django.utils.timezone import utc class Migration(migrations.Migration): @@ -16,7 +15,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='bookuserdata', name='last_changed', - field=models.DateTimeField(default=datetime.datetime(2018, 11, 28, 14, 41, 2, 673054, tzinfo=utc), auto_now=True), + field=models.DateTimeField(default=datetime.datetime(2018, 11, 28, 14, 41, 2, 673054, tzinfo=datetime.timezone.utc), auto_now=True), preserve_default=False, ), ] diff --git a/src/bookmarks/models.py b/src/bookmarks/models.py index ca53cd6c3..ef24e83dc 100644 --- a/src/bookmarks/models.py +++ b/src/bookmarks/models.py @@ -29,18 +29,14 @@ class Bookmark(Syncable, models.Model): return str(self.uuid) def save(self, *args, **kwargs): - # TODO: placeholder. - try: - audio_l = self.book.get_audio_length() - except: - audio_l = 60 - - if self.anchor: - self.mode = 'text' - self.audio_timestamp = self.book.sync_elid(self.anchor) - if self.audio_timestamp: - self.mode = 'audio' - self.anchor = self.book.sync_ts(self.audio_timestamp) or '' + audio_l = self.book.get_audio_length() + if audio_l: + if self.anchor and self.audio_timestamp is None: + self.mode = 'text' + self.audio_timestamp = self.book.sync_elid(self.anchor) + elif not self.anchor and self.audio_timestamp is not None: + self.mode = 'audio' + self.anchor = self.book.sync_ts(self.audio_timestamp) or '' return super().save(*args, **kwargs) @classmethod diff --git a/src/club/models.py b/src/club/models.py index eb1439084..8c6c8db1f 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -1,7 +1,7 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from decimal import Decimal import os import tempfile @@ -12,7 +12,7 @@ from django.core.mail import send_mail, EmailMessage from django.urls import reverse from django.db import models from django import template -from django.utils.timezone import now, utc +from django.utils.timezone import now from django.utils.translation import get_language from django_countries.fields import CountryField from catalogue.utils import get_random_hash @@ -314,7 +314,7 @@ class Membership(models.Model): Contact = apps.get_model('messaging', 'Contact') if self.manual: - Contact.update(email, Level.MANUAL_MEMBER, datetime.combine(self.updated_at, datetime.min.time(), utc)) + Contact.update(email, Level.MANUAL_MEMBER, datetime.combine(self.updated_at, datetime.min.time(), timezone.utc)) else: Contact.reset(email) @@ -497,7 +497,7 @@ class PayUOrder(payu_models.Order): booking_date__year=year ): payments.append({ - 'timestamp': datetime(pa.booking_date.year, pa.booking_date.month, pa.booking_date.day, tzinfo=utc), + 'timestamp': datetime(pa.booking_date.year, pa.booking_date.month, pa.booking_date.day, tzinfo=timezone.utc), 'amount': Decimal(str(pa.debit.amount) + '.00') }) diff --git a/src/funding/models.py b/src/funding/models.py index 81d439df8..36221f156 100644 --- a/src/funding/models.py +++ b/src/funding/models.py @@ -1,7 +1,7 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # -from datetime import date, datetime +from datetime import date from urllib.parse import urlencode from django.conf import settings from django.contrib.sites.models import Site @@ -11,7 +11,7 @@ from django.dispatch import receiver from django.template.loader import render_to_string from django.urls import reverse from django.utils.html import mark_safe -from django.utils.timezone import utc +from django.utils.timezone import now from django.utils.translation import gettext_lazy as _, override from catalogue.models import Book from catalogue.utils import get_random_hash @@ -161,7 +161,7 @@ class Offer(models.Model): 'remaining': self.remaining(), 'current': self.current(), }) - self.notified_end = datetime.utcnow().replace(tzinfo=utc) + self.notified_end = now() self.save() def notify_near(self, force=False): @@ -179,7 +179,7 @@ class Offer(models.Model): 'sum': sum_, 'need': need, }) - self.notified_near = datetime.utcnow().replace(tzinfo=utc) + self.notified_near = now() self.save() def notify_published(self): diff --git a/src/lesmianator/models.py b/src/lesmianator/models.py index e32dd0467..f4c8e3b44 100644 --- a/src/lesmianator/models.py +++ b/src/lesmianator/models.py @@ -9,7 +9,7 @@ from random import randint from django.core.files.base import ContentFile from django.db import models -from django.utils.timezone import utc +from django.utils.timezone import now from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey @@ -38,7 +38,7 @@ class Poem(models.Model): def visit(self): self.view_count += 1 - self.seen_at = datetime.utcnow().replace(tzinfo=utc) + self.seen_at = now() self.save() def __str__(self): diff --git a/src/social/api/views.py b/src/social/api/views.py index 8e09e81c5..a2d92ccf6 100644 --- a/src/social/api/views.py +++ b/src/social/api/views.py @@ -1,10 +1,10 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # -from datetime import datetime +from datetime import datetime, timezone from django.db.models import Q from django.http import Http404 -from django.utils.timezone import now, utc +from django.utils.timezone import now from rest_framework.exceptions import MethodNotAllowed from rest_framework.generics import ListAPIView, ListCreateAPIView, RetrieveAPIView, RetrieveUpdateAPIView, RetrieveUpdateDestroyAPIView, get_object_or_404 from rest_framework.permissions import SAFE_METHODS, IsAuthenticated, IsAuthenticatedOrReadOnly @@ -355,7 +355,7 @@ class SyncView(ListAPIView): except: timestamp = 0 - timestamp = datetime.fromtimestamp(timestamp, tz=utc) + timestamp = datetime.fromtimestamp(timestamp, tz=timezone.utc) data = [] return self.get_queryset_for_ts(timestamp) diff --git a/src/social/models.py b/src/social/models.py index 45ee0f4a6..a8bec9cd5 100644 --- a/src/social/models.py +++ b/src/social/models.py @@ -11,7 +11,7 @@ from django.contrib.auth.models import User from django.core.exceptions import ValidationError from django.core.mail import send_mail from django.urls import reverse -from django.utils.timezone import now, utc +from django.utils.timezone import now from catalogue.models import Book from catalogue.utils import get_random_hash from wolnelektury.utils import cached_render, clear_cached_renders diff --git a/src/social/syncable.py b/src/social/syncable.py index 6447f344b..b86e2fd1a 100644 --- a/src/social/syncable.py +++ b/src/social/syncable.py @@ -1,5 +1,5 @@ -from datetime import datetime -from django.utils.timezone import now, utc +from datetime import datetime, timezone +from django.utils.timezone import now class Syncable: @@ -9,7 +9,7 @@ class Syncable: if ts is None: ts = now() else: - ts = datetime.fromtimestamp(ts, tz=utc) + ts = datetime.fromtimestamp(ts, tz=timezone.utc) if instance is not None: if ts and ts < instance.reported_timestamp: diff --git a/src/wolnelektury/settings/locale.py b/src/wolnelektury/settings/locale.py index 65b8200ea..baeb4e649 100644 --- a/src/wolnelektury/settings/locale.py +++ b/src/wolnelektury/settings/locale.py @@ -7,7 +7,6 @@ from .paths import PROJECT_DIR # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True -USE_L10N = True LOCALE_PATHS = [ path.join(PROJECT_DIR, 'locale') -- 2.20.1 From 4983ea69a6e6c266b0466a851fb4a1ddd27767b4 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 00:17:40 +0100 Subject: [PATCH 07/16] Don't read from STATIC_ROOT directly --- src/club/models.py | 2 +- src/opds/views.py | 8 ++++---- src/reporting/views.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/club/models.py b/src/club/models.py index 8c6c8db1f..792d6c83e 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -515,7 +515,7 @@ class PayUOrder(payu_models.Order): temp = tempfile.NamedTemporaryFile(prefix='receipt-', suffix='.pdf', delete=False) temp.close() render_to_pdf(temp.name, 'club/receipt.texml', ctx, { - "wl.eps": os.path.join(settings.STATIC_ROOT, "img/wl.eps"), + "wl.eps": os.path.join(settings.PROJECT_DIR, "static/img/wl.eps"), }) with open(temp.name, 'rb') as f: diff --git a/src/opds/views.py b/src/opds/views.py index d2d7b6e09..3862c5cd9 100644 --- a/src/opds/views.py +++ b/src/opds/views.py @@ -77,15 +77,15 @@ class OPDSFeed(Atom1Feed): link_rel = "subsection" link_type = "application/atom+xml" - _book_parent_img = lazy(lambda: full_url(os.path.join(settings.STATIC_URL, "img/book-parent.png")), str)() + _book_parent_img = lazy(lambda: full_url(os.path.join(settings.PROJECT_DIR, "static/img/book-parent.png")), str)() try: - _book_parent_img_size = str(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book-parent.png"))) + _book_parent_img_size = str(os.path.getsize(os.path.join(settings.PROJECT_DIR, "static/img/book-parent.png"))) except OSError: _book_parent_img_size = '' - _book_img = lazy(lambda: full_url(os.path.join(settings.STATIC_URL, "img/book.png")), str)() + _book_img = lazy(lambda: full_url(os.path.join(settings.PROJECT_DIR, "static/img/book.png")), str)() try: - _book_img_size = str(os.path.getsize(os.path.join(settings.STATIC_ROOT, "img/book.png"))) + _book_img_size = str(os.path.getsize(os.path.join(settings.PROJECT_DIR, "static/img/book.png"))) except OSError: _book_img_size = '' diff --git a/src/reporting/views.py b/src/reporting/views.py index eb647467d..22c0e522b 100644 --- a/src/reporting/views.py +++ b/src/reporting/views.py @@ -79,7 +79,7 @@ def catalogue_pdf(path): 'orphans': orphans, 'books_by_parent': books_by_parent, }, { - "wl-logo.png": os.path.join(settings.STATIC_ROOT, "img/logo-big.png"), + "wl-logo.png": os.path.join(settings.PROJECT_DIR, "static/img/logo-big.png"), }) -- 2.20.1 From 8a3885e1467e4c441721eaae608755a9fd10b33f Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 13:00:14 +0100 Subject: [PATCH 08/16] Python 3.11, relevant upgrades --- Dockerfile | 2 +- docker-compose.yml | 1 + requirements/requirements.txt | 19 +++---- src/catalogue/fields.py | 4 +- src/wolnelektury/settings/auth.py | 2 +- src/wolnelektury/settings/static.py | 9 +++- src/wolnelektury/utils.py | 78 ----------------------------- 7 files changed, 23 insertions(+), 92 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6debff91..434dade33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ # Global build arguments. Stages using UID/GID must redeclare them # (bare `ARG UID`) to bring them into scope; the defaults are set here. -ARG PYTHON_IMAGE=python:3.10-trixie +ARG PYTHON_IMAGE=python:3.11-trixie ARG UID=8100 ARG GID=8100 diff --git a/docker-compose.yml b/docker-compose.yml index 81df2031d..afa178665 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ x-app-base: &app-base - ./var/counters/:/app/var/counters - ${LIBRARIAN:-/nonexistent}:/${LIBRARIAN:+edita}ble/librarian - ipython:/app/.ipython + - ./var/.bash_history:/app/.bash_history depends_on: - db - redis diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 9c3aa7959..0743b99a6 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -11,13 +11,13 @@ django-pipeline==4.1.0 jsmin==3.0.1 fnp-django-pagination==2.2.12 -django-modeltranslation==0.18.12 -django-allauth[socialaccount,openid]==0.63.6 -django-extensions==3.2.3 -djangorestframework==3.15.1 -django-filter==23.5 +django-modeltranslation==0.19.17 +django-allauth[socialaccount,openid]==65.21.1 +django-extensions==4.1 +djangorestframework==3.17.2 +django-filter==25.1 djangorestframework-xml==2.0.0 -django-admin-ordering==0.18 +django-admin-ordering==0.22 django-countries==7.6.1 django-forms-builder @ git+https://github.com/rczajka/django-forms-builder@6533f9442f004d44ed362202b6bdab82b73dd5e9 @@ -33,9 +33,9 @@ django-honeypot==1.2.1 Feedparser==6.0.14 -Pillow==12.3.0 +Pillow==13.0.0 mutagen==1.48.1 -sorl-thumbnail==12.10.0 +sorl-thumbnail==13.0.0 zipstream-ng==1.9.3 @@ -46,11 +46,12 @@ librarian==26.11 # celery tasks celery[redis]==5.6.2 -oaipmh==3.2.1 +oaipmh==4.0.0 sentry-sdk==2.74.0 requests==2.34.2 +requests_oauthlib==2.0.0 paypalrestsdk diff --git a/src/catalogue/fields.py b/src/catalogue/fields.py index 2d35357eb..ee64ee4d1 100644 --- a/src/catalogue/fields.py +++ b/src/catalogue/fields.py @@ -1,9 +1,9 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # +from importlib.metadata import version import io import os -import pkg_resources import random import time from urllib.request import urlopen @@ -151,7 +151,7 @@ class EbookField(models.FileField): def get_current_etag(self): MediaInsertSet = apps.get_model('annoy', 'MediaInsertSet') - librarian_version = pkg_resources.get_distribution("librarian").version + librarian_version = version("librarian") etag = librarian_version mis = MediaInsertSet.get_for_format(self.ext) if mis is not None: diff --git a/src/wolnelektury/settings/auth.py b/src/wolnelektury/settings/auth.py index 2fe844c6e..0acfa9041 100644 --- a/src/wolnelektury/settings/auth.py +++ b/src/wolnelektury/settings/auth.py @@ -6,7 +6,7 @@ AUTHENTICATION_BACKENDS = [ 'allauth.account.auth_backends.AuthenticationBackend', ] ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 2 -ACCOUNT_AUTHENTICATION_METHOD = "username_email" +ACCOUNT_LOGIN_METHODS = {'email', 'username'} FEATURE_CONFIRM_USER = False LOGIN_URL = '/uzytkownik/login/' diff --git a/src/wolnelektury/settings/static.py b/src/wolnelektury/settings/static.py index 9c2960fbd..505d13916 100644 --- a/src/wolnelektury/settings/static.py +++ b/src/wolnelektury/settings/static.py @@ -144,7 +144,14 @@ PIPELINE = { 'CSSMIN_ARGUMENTS': '--stdin --style=compressed --no-source-map', } -STATICFILES_STORAGE = 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage' +STORAGES = { + 'default': { + 'BACKEND': 'django.core.files.storage.FileSystemStorage' + }, + 'staticfiles': { + 'BACKEND': 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage' + }, +} STATICFILES_FINDERS = [ diff --git a/src/wolnelektury/utils.py b/src/wolnelektury/utils.py index dfa8522f8..245c076b1 100644 --- a/src/wolnelektury/utils.py +++ b/src/wolnelektury/utils.py @@ -4,9 +4,7 @@ import codecs import csv from functools import wraps -from inspect import getargspec from io import BytesIO -import json import os import re @@ -14,7 +12,6 @@ from django.conf import settings from django.contrib import admin from django.core.cache import cache from django.core.mail import send_mail -from django.http import HttpResponse from django.template.loader import render_to_string from django.utils.translation import get_language from django.conf import settings @@ -30,81 +27,6 @@ def makedirs(path): os.makedirs(path) -def stringify_keys(dictionary): - return dict((keyword.encode('ascii'), value) - for keyword, value in dictionary.items()) - - -def json_encode(obj, sort_keys=True, ensure_ascii=False): - return json.dumps(obj, sort_keys=sort_keys, ensure_ascii=ensure_ascii) - - -def json_decode(obj): - return json.loads(obj) - - -def json_decode_fallback(value): - try: - return json_decode(value) - except ValueError: - return value - - -class AjaxError(Exception): - pass - - -def ajax(login_required=False, method=None, template=None, permission_required=None): - def decorator(fun): - @wraps(fun) - def ajax_view(request): - kwargs = {} - request_params = None - if method == 'post': - request_params = request.POST - elif method == 'get': - request_params = request.GET - fun_params, xx, fun_kwargs, defaults = getargspec(fun) - if defaults: - required_params = fun_params[1:-len(defaults)] - else: - required_params = fun_params[1:] - missing_params = set(required_params) - set(request_params) - if missing_params: - res = { - 'result': 'missing params', - 'missing': ', '.join(missing_params), - } - else: - if request_params: - request_params = dict( - (key, json_decode_fallback(value)) - for key, value in request_params.items() - if fun_kwargs or key in fun_params) - kwargs.update(stringify_keys(request_params)) - res = None - if login_required and not request.user.is_authenticated: - res = {'result': 'logout'} - if (permission_required and - not request.user.has_perm(permission_required)): - res = {'result': 'access denied'} - if not res: - try: - res = fun(request, **kwargs) - if res and template: - res = {'html': render_to_string(template, res, request=request)} - except AjaxError as e: - res = {'result': e.args[0]} - if 'result' not in res: - res['result'] = 'ok' - return HttpResponse(json_encode(res), content_type='application/json; charset=utf-8', - status=200 if res['result'] == 'ok' else 400) - - return ajax_view - - return decorator - - def send_noreply_mail(subject, message, recipient_list, **kwargs): send_mail( '[WolneLektury] ' + subject, -- 2.20.1 From f2cb3a436a5a018d37585c86dddf08a009eae0cf Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 14:45:05 +0100 Subject: [PATCH 09/16] Python 3.12 --- Dockerfile | 2 +- requirements/requirements.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 434dade33..3e8d29d2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ # Global build arguments. Stages using UID/GID must redeclare them # (bare `ARG UID`) to bring them into scope; the defaults are set here. -ARG PYTHON_IMAGE=python:3.11-trixie +ARG PYTHON_IMAGE=python:3.12-trixie ARG UID=8100 ARG GID=8100 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 0743b99a6..88e374b11 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -2,7 +2,7 @@ # django Django==4.2.30 -fnpdjango==0.7 +fnpdjango==0.8 docutils==0.23 pymemcache==4.0.0 @@ -10,7 +10,7 @@ pymemcache==4.0.0 django-pipeline==4.1.0 jsmin==3.0.1 -fnp-django-pagination==2.2.12 +fnp-django-pagination==2.2.13 django-modeltranslation==0.19.17 django-allauth[socialaccount,openid]==65.21.1 django-extensions==4.1 -- 2.20.1 From 58330dfed381953a0ccf6d31ff57c387cad23be7 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 16:43:32 +0100 Subject: [PATCH 10/16] Django 5.2 --- Dockerfile | 4 ---- requirements/requirements-dev.txt | 6 ------ requirements/requirements.txt | 17 ++++++++++------- src/catalogue/models/book.py | 3 ++- src/oai/handlers.py | 8 ++++---- src/wolnelektury/settings/basic.py | 2 ++ src/wolnelektury/templates/admin/base_site.html | 2 +- 7 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 requirements/requirements-dev.txt diff --git a/Dockerfile b/Dockerfile index 3e8d29d2f..d9a71d9b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,10 +50,6 @@ COPY requirements/requirements.txt requirements.txt RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r requirements.txt -RUN --mount=type=cache,target=/root/.cache/pip \ - pip install \ - psycopg2-binary \ - django-debug-toolbar==3.2.2 RUN addgroup --gid $GID app && \ adduser --gid $GID --home /app --uid $UID app diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt deleted file mode 100644 index 5b58a1fe5..000000000 --- a/requirements/requirements-dev.txt +++ /dev/null @@ -1,6 +0,0 @@ --i https://py.mdrn.pl/simple/ - -django-debug-toolbar -django-debug-toolbar-template-timings -sphinx -pyinotify diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 88e374b11..cbcc31b17 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,9 +1,11 @@ -i https://py.mdrn.pl/simple/ # django -Django==4.2.30 +Django==5.2.19 fnpdjango==0.8 docutils==0.23 +django-debug-toolbar==8.0.0 +psycopg2-binary==2.9.13 pymemcache==4.0.0 @@ -11,14 +13,15 @@ django-pipeline==4.1.0 jsmin==3.0.1 fnp-django-pagination==2.2.13 -django-modeltranslation==0.19.17 +django-modeltranslation==0.20.6 django-allauth[socialaccount,openid]==65.21.1 django-extensions==4.1 -djangorestframework==3.17.2 -django-filter==25.1 +djangorestframework==3.18.3 +django-filter==26.2 djangorestframework-xml==2.0.0 django-admin-ordering==0.22 -django-countries==7.6.1 +django-countries==9.1.0 + django-forms-builder @ git+https://github.com/rczajka/django-forms-builder@6533f9442f004d44ed362202b6bdab82b73dd5e9 @@ -29,13 +32,13 @@ pyyaml==6.0.3 polib==1.2 -django-honeypot==1.2.1 +django-honeypot==1.3.0 Feedparser==6.0.14 Pillow==13.0.0 mutagen==1.48.1 -sorl-thumbnail==13.0.0 +sorl-thumbnail==13.4.0 zipstream-ng==1.9.3 diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index e9050d0c4..d09a09a43 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -228,7 +228,8 @@ class Book(models.Model): if self.preview and not self.preview_key: self.preview_key = get_random_hash(self.slug)[:32] - ret = super(Book, self).save(force_insert, force_update, **kwargs) + ret = super(Book, self).save( + force_insert=force_insert, force_update=force_update, **kwargs) return ret diff --git a/src/oai/handlers.py b/src/oai/handlers.py index c67044952..7ac3f8fea 100644 --- a/src/oai/handlers.py +++ b/src/oai/handlers.py @@ -1,13 +1,13 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # -from datetime import datetime +from datetime import datetime, timezone from lxml import etree from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site -from django.utils import timezone +from django.utils.timezone import localtime, make_aware from oaipmh import server, common, metadata, error from api.handlers import WL_BASE @@ -17,7 +17,7 @@ from librarian import WLURI def make_time_naive(d): - return timezone.localtime(d).replace(tzinfo=None) + return localtime(d).replace(tzinfo=None) WL_DC_READER_XPATH = '(.|*)/rdf:RDF/rdf:Description/%s/text()' wl_dc_reader = metadata.MetadataReader( @@ -65,7 +65,7 @@ class Catalogue(common.ResumptionOAIPMH): self.oai_id = "oai:" + Site.objects.get_current().domain + ":%s" # earliest change - year_zero = timezone.make_aware(datetime(1990, 1, 1, 0, 0, 0), timezone.utc) + year_zero = make_aware(datetime(1990, 1, 1, 0, 0, 0), timezone.utc) try: earliest_change = Book.objects.filter(findable=True, preview=False).order_by('changed_at')[0].changed_at diff --git a/src/wolnelektury/settings/basic.py b/src/wolnelektury/settings/basic.py index 1b86642e3..86a1a8f54 100644 --- a/src/wolnelektury/settings/basic.py +++ b/src/wolnelektury/settings/basic.py @@ -124,3 +124,5 @@ MIDDLEWARE = [ ROOT_URLCONF = 'wolnelektury.urls' FILE_UPLOAD_PERMISSIONS = 0o640 + +FORMS_URLFIELD_ASSUME_HTTPS = True diff --git a/src/wolnelektury/templates/admin/base_site.html b/src/wolnelektury/templates/admin/base_site.html index c23c03171..eecf3b255 100644 --- a/src/wolnelektury/templates/admin/base_site.html +++ b/src/wolnelektury/templates/admin/base_site.html @@ -3,7 +3,7 @@ {% block title %}{{ title }} | Administracja - WolneLektury.pl{% endblock %} {% block branding %} -

Administracja - WolneLektury.pl

+
Administracja - WolneLektury.pl

promobox | bannery | -- 2.20.1 From 111a23185d6f47f692540fb145dc5604c47aee67 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Nov 2026 16:59:09 +0100 Subject: [PATCH 11/16] fixes --- src/bookmarks/api/views.py | 2 +- src/pdcounter/templatetags/time_tags.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bookmarks/api/views.py b/src/bookmarks/api/views.py index 1280ad552..335e0e70c 100644 --- a/src/bookmarks/api/views.py +++ b/src/bookmarks/api/views.py @@ -132,7 +132,7 @@ class QuoteSerializer(serializers.ModelSerializer): class Meta: model = models.Quote - fields = ['book_slug', 'book', + fields = ['book_slug', 'book', 'text', 'start_elem', 'start_offset', 'end_elem', 'end_offset', 'href', 'uuid', 'timestamp', 'deleted'] read_only_fields = ['uuid', 'mode'] diff --git a/src/pdcounter/templatetags/time_tags.py b/src/pdcounter/templatetags/time_tags.py index 6ec0b80a0..98a2facfd 100644 --- a/src/pdcounter/templatetags/time_tags.py +++ b/src/pdcounter/templatetags/time_tags.py @@ -21,7 +21,7 @@ def date_to_utc(date, day_end=False): date += datetime.timedelta(1) localtime = datetime.datetime.combine(date, datetime.time(0, 0), timezone.get_current_timezone()) - return timezone.localtime(localtime, timezone.utc) + return timezone.localtime(localtime, datetime.timezone.utc) @register.filter -- 2.20.1 From db85a925446ab8082ead1e84d13d2fcf57603e83 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 13 Nov 2026 11:37:36 +0100 Subject: [PATCH 12/16] Up forms builder --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index cbcc31b17..92fb217dc 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -23,7 +23,7 @@ django-admin-ordering==0.22 django-countries==9.1.0 -django-forms-builder @ git+https://github.com/rczajka/django-forms-builder@6533f9442f004d44ed362202b6bdab82b73dd5e9 +django-forms-builder @ git+https://github.com/rczajka/django-forms-builder@8364d3d1d460e015b045705cfbc87019e8d8a620 oauthlib==4.0.1 -- 2.20.1 From 5707b617718c2a5c9bc97e90aff2d38a4717528d Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 17 Nov 2026 11:37:43 +0100 Subject: [PATCH 13/16] bugfix for Django 5: QuerySet in FilteredRelation --- src/catalogue/views.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 8d32e64ee..b8f42b1e6 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -73,7 +73,7 @@ def differentiate_tags(request, tags, ambiguous_slugs): ) -from django.db.models import FilteredRelation, Q +from django.db.models import Q from django.views.decorators.cache import cache_control from django.views.decorators.vary import vary_on_headers from django.utils.decorators import method_decorator @@ -187,10 +187,8 @@ class BookList(ObjectListView): Q(text__icontains=term) ).distinct() else: - qs = qs.annotate( - meta=FilteredRelation('tag_relations', condition=Q(tag_relations__in=meta_rels)) - ) - qs = qs.filter(Q(title__icontains=term) | Q(meta__tag__name_pl__icontains=term)).distinct() + rels = meta_rels.filter(tag__name_pl__icontains=term) + qs = qs.filter(Q(title__icontains=term) | Q(tag_relations__in=rels)).distinct() return qs -- 2.20.1 From 1aa23677658744856f96a31492487683dcd80ca5 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 17 Nov 2026 12:16:39 +0100 Subject: [PATCH 14/16] Paypal fix --- src/paypal/rest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/paypal/rest.py b/src/paypal/rest.py index a5e7ebeee..cf80b46e1 100644 --- a/src/paypal/rest.py +++ b/src/paypal/rest.py @@ -1,12 +1,12 @@ # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # -from datetime import date, datetime, timedelta +from datetime import date, datetime, timedelta, timezone from decimal import Decimal import paypalrestsdk from django.contrib.sites.models import Site from django.urls import reverse -from django.utils import timezone +from django.utils.timezone import now from django.conf import settings from .models import BillingPlan, BillingAgreement @@ -69,7 +69,7 @@ def create_agreement(amount, key, app=False): plan_id = create_plan(amount) else: plan_id = plan.plan_id - start = (timezone.now() + timedelta(0, 3600*24)).astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') + start = (now() + timedelta(0, 3600*24)).astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') billing_agreement = paypalrestsdk.BillingAgreement({ "name": "Subskrypcja klubu WL", "description": "Stałe wsparcie Wolnych Lektur kwotą %s złotych" % amount, -- 2.20.1 From 7193ffdc9dab1b70030c491b972d972ee32c0abe Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 23 Nov 2026 14:07:54 +0100 Subject: [PATCH 15/16] Missing well-known files --- Dockerfile | 7 ++++--- docker-compose.yml | 4 ++-- scripts/{ => nginx}/nginx.conf | 8 +++++--- .../nginx/well-known/apple-app-site-association | 13 +++++++++++++ scripts/nginx/well-known/assetlinks.json | 14 ++++++++++++++ scripts/{ => postgres}/fold_hunspell.py | 0 scripts/{ => postgres}/postgres-polish.sql | 0 7 files changed, 38 insertions(+), 8 deletions(-) rename scripts/{ => nginx}/nginx.conf (93%) create mode 100644 scripts/nginx/well-known/apple-app-site-association create mode 100644 scripts/nginx/well-known/assetlinks.json rename scripts/{ => postgres}/fold_hunspell.py (100%) rename scripts/{ => postgres}/postgres-polish.sql (100%) diff --git a/Dockerfile b/Dockerfile index d9a71d9b0..1722739a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -111,7 +111,8 @@ FROM nginx:alpine AS nginx ARG UID ARG GID -# COPY nginx.conf conf.d/... +COPY scripts/nginx/nginx.conf /etc/nginx/conf.d/default.conf +COPY scripts/nginx/well-known /app/.well-known RUN addgroup -g $GID app && addgroup nginx app COPY --from=static-builder /app/var/static /app/var/static @@ -129,7 +130,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends hunspell-pl \ && rm -rf /var/lib/apt/lists/* -COPY scripts/fold_hunspell.py /usr/local/bin/fold_hunspell.py +COPY scripts/postgres/fold_hunspell.py /usr/local/bin/fold_hunspell.py RUN set -eu; \ mkdir /out; cd /tmp; \ @@ -152,7 +153,7 @@ COPY --from=polish-dict /out/ /tmp/polish-dict/ RUN mv /tmp/polish-dict/* "/usr/share/postgresql/$PG_MAJOR/tsearch_data/" \ && rmdir /tmp/polish-dict -COPY scripts/postgres-polish.sql /docker-entrypoint-initdb.d/10-postgres-polish.sql +COPY scripts/postgres/postgres-polish.sql /docker-entrypoint-initdb.d/10-postgres-polish.sql ########## diff --git a/docker-compose.yml b/docker-compose.yml index afa178665..025589fe5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,7 +30,7 @@ services: command: python -Wall ./manage.py runserver 0.0.0.0:8000 ports: # Dev: use http://localhost:8000/ directly - - "127.0.0.1:8000:8000" + - "8000:8000" celery: <<: *app-base @@ -65,7 +65,7 @@ services: - "127.0.0.1:8101:80" volumes: - ./var/media:/app/var/media:ro - - ./scripts/nginx.conf:/etc/nginx/conf.d/default.conf:ro + - ./scripts/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro depends_on: - web diff --git a/scripts/nginx.conf b/scripts/nginx/nginx.conf similarity index 93% rename from scripts/nginx.conf rename to scripts/nginx/nginx.conf index 561a5d4e4..a34ef5575 100644 --- a/scripts/nginx.conf +++ b/scripts/nginx/nginx.conf @@ -9,20 +9,22 @@ server { proxy_buffers 16 16k; proxy_buffer_size 32k; + root /app/var; + + location /.well-known/ {} + location /static/ { - root /app/var; expires 30d; } location /media/ { - root /app/var; expires 30d; } location ~ ^/media/.*\.(mp3|ogg|daisy\.zip)$ { add_header Content-Disposition "attachment"; } location ~ ^/media/.*\.txt$ { - add_header Content-Type "text/plain; charset=utf-8"; + charset utf-8; } location ~ ^/media/book/(pdf|epub|mobi|fb2|cover|xml)/ { # kill cache diff --git a/scripts/nginx/well-known/apple-app-site-association b/scripts/nginx/well-known/apple-app-site-association new file mode 100644 index 000000000..afeaa3e14 --- /dev/null +++ b/scripts/nginx/well-known/apple-app-site-association @@ -0,0 +1,13 @@ +{ + "applinks": { + "apps": [], + "details": [ + { + "appID": "WX9PLY5GYU.pl.app.wolnelektury", + "paths": [ + "/*" + ] + } + ] + } +} \ No newline at end of file diff --git a/scripts/nginx/well-known/assetlinks.json b/scripts/nginx/well-known/assetlinks.json new file mode 100644 index 000000000..9154b21b1 --- /dev/null +++ b/scripts/nginx/well-known/assetlinks.json @@ -0,0 +1,14 @@ +[ + { + "relation": [ + "delegate_permission/common.handle_all_urls" + ], + "target": { + "namespace": "android_app", + "package_name": "pl.app.wolnelektury", + "sha256_cert_fingerprints": [ + "4F:5E:3E:70:18:02:00:AF:7F:91:93:65:DC:55:B1:2D:81:C8:DF:62:9C:22:00:C3:D8:52:33:DF:41:E5:2C:BF" + ] + } + } +] diff --git a/scripts/fold_hunspell.py b/scripts/postgres/fold_hunspell.py similarity index 100% rename from scripts/fold_hunspell.py rename to scripts/postgres/fold_hunspell.py diff --git a/scripts/postgres-polish.sql b/scripts/postgres/postgres-polish.sql similarity index 100% rename from scripts/postgres-polish.sql rename to scripts/postgres/postgres-polish.sql -- 2.20.1 From 7956a3378cddda6f12b225e483d3c2281c9db154 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 23 Nov 2026 14:13:07 +0100 Subject: [PATCH 16/16] fix --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1722739a6..4264e9d7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -112,7 +112,7 @@ ARG UID ARG GID COPY scripts/nginx/nginx.conf /etc/nginx/conf.d/default.conf -COPY scripts/nginx/well-known /app/.well-known +COPY scripts/nginx/well-known /app/var/.well-known RUN addgroup -g $GID app && addgroup nginx app COPY --from=static-builder /app/var/static /app/var/static -- 2.20.1