Paypal fix master
authorRadek Czajka <radekczajka@wolnelektury.pl>
Tue, 17 Nov 2026 11:16:39 +0000 (12:16 +0100)
committerRadek Czajka <radekczajka@wolnelektury.pl>
Tue, 17 Nov 2026 11:16:39 +0000 (12:16 +0100)
61 files changed:
.dockerignore [new file with mode: 0644]
.gitignore
Dockerfile
Makefile
docker-compose.test.yml [new file with mode: 0644]
docker-compose.yml
requirements/requirements-dev.txt [deleted file]
requirements/requirements.txt
scripts/fold_hunspell.py [new file with mode: 0644]
scripts/nginx.conf [new file with mode: 0644]
scripts/postgres-polish.sql [new file with mode: 0644]
src/api/migrations/0004_bookuserdata_last_changed.py
src/api/tests/tests.py
src/bookmarks/api/views.py
src/bookmarks/models.py
src/catalogue/api/fields.py
src/catalogue/fields.py
src/catalogue/fixtures/test-books.yaml
src/catalogue/models/book.py
src/catalogue/models/snippet.py
src/catalogue/templates/catalogue/book_detail.html
src/catalogue/templates/catalogue/book_text.html
src/catalogue/templatetags/catalogue_tags.py
src/catalogue/test_utils.py
src/catalogue/views.py
src/club/models.py
src/dictionary/tests.py
src/funding/models.py
src/lesmianator/models.py
src/oai/handlers.py
src/opds/tests/test_opds.py
src/opds/views.py
src/paypal/rest.py
src/pdcounter/templatetags/time_tags.py
src/reporting/views.py
src/search/utils.py
src/search/views.py
src/social/api/serializers.py
src/social/api/views.py
src/social/models.py
src/social/syncable.py
src/sponsors/models.py
src/stats/models.py
src/wolnelektury/settings/auth.py
src/wolnelektury/settings/basic.py
src/wolnelektury/settings/locale.py
src/wolnelektury/settings/static.py
src/wolnelektury/settings/test.py
src/wolnelektury/static/2022/styles/components/_media.scss
src/wolnelektury/static/2022/styles/layout/_books.scss
src/wolnelektury/static/2022/styles/layout/_footer.scss
src/wolnelektury/static/2022/styles/layout/_navigation.scss
src/wolnelektury/static/2022/styles/layout/_quotes.scss
src/wolnelektury/static/2022/styles/layout/_your-books.scss
src/wolnelektury/static/js/main.js
src/wolnelektury/templates/account/base.html [deleted file]
src/wolnelektury/templates/admin/base_site.html
src/wolnelektury/templates/allauth/layouts/base.html [new file with mode: 0644]
src/wolnelektury/templates/header.html
src/wolnelektury/templates/user_actions.html
src/wolnelektury/utils.py

diff --git a/.dockerignore b/.dockerignore
new file mode 100644 (file)
index 0000000..6d8372f
--- /dev/null
@@ -0,0 +1,7 @@
+**/__pycache__
+**/*~
+**/#*#
+**/.#*
+src/wolnelektury/localsettings.py
+src/wolnelektury/dev.db
+
index 3d746f9..6c61236 100644 (file)
@@ -1,4 +1,5 @@
 localsettings.py
+.env
 dev.sqlite
 *.db
 *.db-journal
index b23530b..d9a71d9 100644 (file)
@@ -1,7 +1,32 @@
-FROM python:3.9-trixie AS base
+# Wolne Lektury images.
+#
+# Stages marked with ##### are build targets:
+#   deps      dev image (docker-compose.yml, code mounted)
+#   test      docker-compose.test.yml
+#   prod      production app image (default, last stage)
+#   nginx     production nginx with static files
+#   postgres  Postgres with Polish dictionary
+# Stages marked with ===== are intermediate.
 
-ARG UID=1000
-ARG GID=1000
+
+# 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.12-trixie
+ARG UID=8100
+ARG GID=8100
+
+
+##########
+#  deps  #############################################################
+#
+#  Base system and requirements.
+#  Used directly as the dev image, with code mounted.
+#
+FROM ${PYTHON_IMAGE} AS deps
+
+ARG UID
+ARG GID
 
 RUN     apt-get update && apt-get install -y \
        git \
@@ -15,13 +40,16 @@ 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
 
-RUN pip install --no-cache-dir -r requirements.txt
-RUN pip install --no-cache-dir \
-    psycopg2-binary \
-    django-debug-toolbar==3.2.2
+RUN --mount=type=cache,target=/root/.cache/pip \
+    pip install -r requirements.txt
 
 RUN addgroup --gid $GID app && \
     adduser --gid $GID --home /app --uid $UID app
@@ -38,36 +66,118 @@ WORKDIR /app/src
 RUN mkdir /app/.ipython
 
 
+#=======#
+#  app  #=============================================================
+#
+#  Code and production requirements. Not production yet: needs
+#  staticfiles.json manifest from static-builder.
+#
+FROM deps AS app
 
+USER root
 
-FROM base AS dev
-
-#RUN pip install --no-cache-dir coverage
+RUN --mount=type=cache,target=/root/.cache/pip \
+    pip install gunicorn
 
+USER app
 
+COPY src /app/src
 
 
-FROM base AS prod
+#==================#
+#  static-builder  #==================================================
+#
+#  Static files are collected here. Statics are then copied into
+#  the nginx image, and staticfiles.json manifest is copied back
+#  into the test and prod images.
+#
+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 pip install --no-cache-dir gunicorn
+RUN python manage.py collectstatic --noinput
 
-USER app
 
-COPY src /app/src
+###########
+#  nginx  ############################################################
+#
+#  Static files for production nginx. Config is mounted.
+#
+FROM nginx:alpine AS nginx
+
+ARG UID
+ARG GID
 
+# COPY nginx.conf conf.d/...
 
+RUN addgroup -g $GID app && addgroup nginx app
+COPY --from=static-builder /app/var/static /app/var/static
 
 
-FROM prod AS static-builder
+#===============#
+#  polish-dict  #=====================================================
+#
+#  Polish hunspell dictionary without diacritics, to allow
+#  full text search without diacritics.
+#
+FROM ${PYTHON_IMAGE} AS polish-dict
 
-RUN python manage.py collectstatic --noinput
+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
 
+RUN set -eu; \
+    mkdir /out; cd /tmp; \
+    enc="$(sed -n 's/^SET[[:space:]]*//p' /usr/share/hunspell/pl_PL.aff | tr -d '\r')"; \
+    iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.dic > pl.dict; \
+    iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.aff > pl.affix; \
+    python3 /usr/local/bin/fold_hunspell.py pl.dict pl.affix \
+        /out/polish.dict /out/polish.affix; \
+    dpkg-query -W -f='hunspell-pl ${Version}\n' hunspell-pl > /out/polish.version
 
-FROM nginx:alpine AS nginx
 
-# COPY nginx.conf conf.d/...
+##############
+#  postgres  #########################################################
+#
+#  Postgres with the dictionary from polish-dict.
+#
+FROM postgres:18 AS postgres
 
-COPY --from=static-builder /app/var/static /app/var/static
+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
+
+
+##########
+#  test  #############################################################
+#
+#  Production image plus test requirements. Defined before `prod`,
+#  so that `prod` stays the default (last) stage.
+#
+FROM app AS test
+
+USER root
+COPY requirements/requirements-test.txt /tmp/
+RUN --mount=type=cache,target=/root/.cache/pip \
+    pip install -r /tmp/requirements-test.txt
+USER app
+RUN mkdir -p /app/var/counters
+COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json
+CMD ["./manage.py", "test"]
+
+
+##########
+#  prod  #############################################################
+#
+#  Production image: app + staticfiles.json manifest.
+#
+FROM app AS prod
+
+COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json
index 59e222a..3f1b3c4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,15 +12,14 @@ deploy: src/wolnelektury/localsettings.py
        src/manage.py collectstatic --noinput
 
 
-.ONESHELL:
+TEST_COMPOSE := docker compose -f docker-compose.test.yml
+
 test:
-       cd src
-       python -Wall -m coverage run --branch --source='.' ./manage.py test; true
-       coverage html -d ../htmlcov.new
-       rm -rf ../htmlcov
-       mv ../htmlcov.new ../htmlcov
-       coverage report
-       rm .coverage
+       mkdir -p htmlcov
+       UID=$(UID) GID=$(GID) $(TEST_COMPOSE) run --rm --build test sh -c '\
+         python -Wall -m coverage run --branch --source=. ./manage.py test $(ARGS); s=$$?; \
+         coverage report --skip-covered; coverage html -d /app/htmlcov; exit $$s'; \
+       status=$$?; $(TEST_COMPOSE) down; exit $$status
 
 
 up:
diff --git a/docker-compose.test.yml b/docker-compose.test.yml
new file mode 100644 (file)
index 0000000..11c6697
--- /dev/null
@@ -0,0 +1,31 @@
+#   make test
+#   make test ARGS=catalogue
+
+name: wolnelektury-test
+
+x-env: &env
+  POSTGRES_USER: wl
+  POSTGRES_PASSWORD: wl
+
+services:
+  test:
+    build:
+      context: .
+      target: test
+      args:
+        UID: ${UID:-1000}
+        GID: ${GID:-1000}
+    environment:
+      <<: *env
+      SECRET_KEY: test
+      ALLOWED_HOSTS: "*"
+      COVERAGE_FILE: /tmp/.coverage
+    volumes:
+      - ./htmlcov:/app/htmlcov
+    depends_on: [db]
+
+  db:
+    build: {context: ., target: postgres}
+    environment: *env
+    tmpfs: [/var/lib/postgresql]
+
index bda15bb..afa1786 100644 (file)
@@ -1,7 +1,7 @@
 x-app-base: &app-base
   build:
     context: .
-    target: dev
+    target: deps
     args:
       UID: ${UID:-1000}
       GID: ${GID:-1000}
@@ -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
@@ -26,16 +27,19 @@ x-app-base: &app-base
 services:
   web:
     <<: *app-base
+    command: python -Wall ./manage.py runserver 0.0.0.0:8000
     ports:
-     - "8000:8000"
-    command: ./manage.py runserver 0.0.0.0:8000
+      # Dev: use http://localhost:8000/ directly
+      - "127.0.0.1:8000:8000"
 
   celery:
     <<: *app-base
     command: celery -A wolnelektury worker -l info
 
   db:
-    image: postgres:18
+    build:
+      context: .
+      target: postgres
     env_file:
       - .env
     volumes:
@@ -47,6 +51,24 @@ services:
   memcached:
     image: memcached:1.6-alpine
 
+  nginx:
+    # Just for testing production-like environment.
+    # docker compose --profile nginx up
+    profiles: ["nginx"]
+    build:
+      context: .
+      target: nginx
+      args:
+        UID: ${UID:-1000}
+        GID: ${GID:-1000}
+    ports:
+      - "127.0.0.1:8101:80"
+    volumes:
+      - ./var/media:/app/var/media:ro
+      - ./scripts/nginx.conf:/etc/nginx/conf.d/default.conf:ro
+    depends_on:
+      - web
+
 
 volumes:
-  ipython:
\ No newline at end of file
+  ipython:
diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt
deleted file mode 100644 (file)
index 9be0df9..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
--i https://py.mdrn.pl/simple/
-
-django-debug-toolbar==3.2.2
-django-debug-toolbar-template-timings
-sphinx
-pyinotify
index 600ec63..92fb217 100644 (file)
@@ -1,67 +1,66 @@
 -i https://py.mdrn.pl/simple/
 
 # django
-Django==4.0.8
-fnpdjango==0.6
-docutils==0.20
+Django==5.2.19
+fnpdjango==0.8
+docutils==0.23
+django-debug-toolbar==8.0.0
+psycopg2-binary==2.9.13
 
-python-memcached==1.59
+pymemcache==4.0.0
 
-django-pipeline==3.1.0
-libsasscompiler==0.2.0
+django-pipeline==4.1.0
 jsmin==3.0.1
 
-fnp-django-pagination==2.2.5
-django-modeltranslation==0.18.12
-django-allauth==0.51
-django-extensions==3.2.3
-djangorestframework==3.15.1
-django-filter==23.5
+fnp-django-pagination==2.2.13
+django-modeltranslation==0.20.6
+django-allauth[socialaccount,openid]==65.21.1
+django-extensions==4.1
+djangorestframework==3.18.3
+django-filter==26.2
 djangorestframework-xml==2.0.0
-django-admin-ordering==0.18
-django-countries==7.6.1
+django-admin-ordering==0.22
+django-countries==9.1.0
 
--e git+https://github.com/rczajka/django-forms-builder@270cc22f80ec4681735b4e01689562fbab79ceda#egg=django-forms-builder
 
+django-forms-builder @ git+https://github.com/rczajka/django-forms-builder@8364d3d1d460e015b045705cfbc87019e8d8a620
 
-oauthlib>=3.0.1,<3.1
+oauthlib==4.0.1
 
 # contact
 pyyaml==6.0.3
 
 polib==1.2
 
-django-honeypot==1.2.1
+django-honeypot==1.3.0
 
-python-fb==0.2
+Feedparser==6.0.14
 
-Feedparser==6.0.11
+Pillow==13.0.0
+mutagen==1.48.1
+sorl-thumbnail==13.4.0
 
-Pillow==9.5.0
-mutagen==1.47
-sorl-thumbnail==12.10.0
-
-zipstream-ng==1.9.2
+zipstream-ng==1.9.3
 
 # home-brewed & dependencies
-librarian==26.5.1
+
+librarian==26.11
 
 # celery tasks
-celery[redis]==5.4.0
+celery[redis]==5.6.2
 
-# OAI-PMH
-#pyoai==2.5.1
--e git+https://github.com/infrae/pyoai@5ff2f15e869869e70d8139e4c37b7832854d7049#egg=pyoai
+oaipmh==4.0.0
 
-sentry-sdk==2.19.2
+sentry-sdk==2.74.0
 
-requests==2.32.3
+requests==2.34.2
+requests_oauthlib==2.0.0
 
 paypalrestsdk
 
-python-slugify==8.0.4
+python-slugify==9.1.3
 
-firebase-admin==6.6.0
+firebase-admin==7.7.0
 Wikidata==0.9.0
 
 ipython
diff --git a/scripts/fold_hunspell.py b/scripts/fold_hunspell.py
new file mode 100644 (file)
index 0000000..bc63e78
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+"""
+Tworzy wersję słownika hunspell bez polskich znaków dla PostgreSQL (szablon ispell).
+
+Użycie:
+    fold_hunspell.py polish.dict polish.affix polish_ascii.dict polish_ascii.affix
+
+Pliki wejściowe muszą być w UTF-8 (po iconv z ISO-8859-2).
+
+Samo usunięcie znaków psuje warunki reguł z klasami negowanymi: np.
+`SFX H ć ło [^ąeśź]ć` (wszystko poza ą, e, ś, ź przed ć) po zamianie
+stałoby się `[^aesz]c` i przestało pasować do czasowników na -ać.
+Dlatego litera zostaje w klasie negowanej tylko wtedy, gdy oryginał
+wykluczał wszystkie litery, które się na nią składają; w przeciwnym
+razie jest usuwana, a pusta klasa zamienia się w `.`. Reguły stają się
+przez to nieco zbyt liberalne (nadmiarowe formy), ale żadna forma nie ginie.
+"""
+import re
+import sys
+import unicodedata
+
+
+def fold(text):
+    text = text.replace('ł', 'l').replace('Ł', 'L')
+    return ''.join(
+        c for c in unicodedata.normalize('NFKD', text)
+        if not unicodedata.combining(c)
+    )
+
+
+LETTERS = 'aąbcćdeęfghijklłmnńoóprsśtuvwxyzźż'
+GROUPS = {}
+for letter in LETTERS:
+    GROUPS.setdefault(fold(letter), set()).add(letter)
+
+
+def fold_negated_class(match):
+    excluded = set(match.group(1))
+    keep = []
+    for c in match.group(1):
+        folded = fold(c)
+        if GROUPS.get(folded, {c}) <= excluded and folded not in keep:
+            keep.append(folded)
+    return '[^' + ''.join(keep) + ']' if keep else '.'
+
+
+def fold_affix_line(line):
+    parts = line.split()
+    if len(parts) >= 5 and parts[0] in ('SFX', 'PFX') and '[^' in parts[4]:
+        condition = re.sub(r'\[\^([^\]]*)\]', fold_negated_class, parts[4])
+        line = line.replace(parts[4], condition, 1)
+    if line.startswith('SET '):
+        return 'SET UTF-8\n'
+    return fold(line)
+
+
+def main(dict_in, affix_in, dict_out, affix_out):
+    with open(dict_in, encoding='utf-8') as src, open(dict_out, 'w', encoding='utf-8') as dst:
+        dst.write(fold(src.read()))
+    with open(affix_in, encoding='utf-8') as src, open(affix_out, 'w', encoding='utf-8') as dst:
+        for line in src:
+            dst.write(fold_affix_line(line))
+
+
+if __name__ == '__main__':
+    main(*sys.argv[1:5])
diff --git a/scripts/nginx.conf b/scripts/nginx.conf
new file mode 100644 (file)
index 0000000..561a5d4
--- /dev/null
@@ -0,0 +1,60 @@
+server {
+    listen 80;
+
+    access_log off;
+    error_log /dev/stderr warn;
+
+    client_max_body_size 4G;
+    send_timeout 300s;
+    proxy_buffers 16 16k;
+    proxy_buffer_size 32k;
+
+    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";
+    }
+    location ~ ^/media/book/(pdf|epub|mobi|fb2|cover|xml)/ {
+        # kill cache
+        add_header Last-Modified $date_gmt;
+        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
+        if_modified_since off;
+        expires off;
+        etag off;
+    }
+
+    location /api/ {
+        add_header 'Access-Control-Allow-Origin' '*' always;
+        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE' always;
+        add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always;
+        add_header 'Access-Control-Expose-Headers' 'Link' always;
+
+        if ($request_method = OPTIONS) {
+            return 204;
+        }
+
+        proxy_set_header Accept-Language "";
+        proxy_set_header Host $host;
+        proxy_pass http://web:8000;
+    }
+    location / {
+       root /app/var/static/root;
+       try_files $uri @backend;
+    }
+
+    location @backend {
+        proxy_set_header Accept-Language "";
+        proxy_set_header Host $host;
+        proxy_pass http://web:8000;
+    }
+}
diff --git a/scripts/postgres-polish.sql b/scripts/postgres-polish.sql
new file mode 100644 (file)
index 0000000..100764a
--- /dev/null
@@ -0,0 +1,27 @@
+CREATE EXTENSION IF NOT EXISTS unaccent;
+
+DO $$
+  BEGIN
+  IF NOT EXISTS (SELECT 1 FROM pg_ts_dict
+               WHERE dictname = 'polish_hunspell'
+                 AND dictnamespace = 'public'::regnamespace) THEN
+    CREATE TEXT SEARCH DICTIONARY public.polish_hunspell (
+        TEMPLATE = ispell, DictFile = polish, AffFile = polish
+    );
+  END IF;
+  IF NOT EXISTS (SELECT 1 FROM pg_ts_config
+                      WHERE cfgname = 'polish'
+               AND cfgnamespace = 'public'::regnamespace) THEN
+    CREATE TEXT SEARCH CONFIGURATION public.polish (COPY = pg_catalog.simple);
+  END IF;
+END $$;
+
+ALTER TEXT SEARCH DICTIONARY public.polish_hunspell (
+  DictFile = polish, AffFile = polish, StopWords
+);
+
+ALTER TEXT SEARCH CONFIGURATION public.polish
+  ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
+  WITH unaccent, polish_hunspell, simple;
+
+
index 1e6f047..fe6f940 100644 (file)
@@ -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,
         ),
     ]
index 63ac8d7..27b98c1 100644 (file)
@@ -416,7 +416,7 @@ class AuthorizedTests(ApiTest):
         self.assert_slugs('/api/preview/', ['grandchild'])
         self.assertEqual(
             self.signed_json('/api/username/'),
-            {"username": "test", "premium": False})
+            {"username": "test", "confirmed": True, "premium": False})
         self.assertEqual(
             self.signed('/api/epub/grandchild/').status_code,
             403)
@@ -424,7 +424,7 @@ class AuthorizedTests(ApiTest):
         with patch('club.models.Membership.is_active_for', return_value=True):
             self.assertEqual(
                 self.signed_json('/api/username/'),
-                {"username": "test", "premium": True})
+                {"username": "test", "confirmed": True, "premium": True})
             with patch('django.core.files.storage.Storage.open',
                        return_value=BytesIO(b"<epub>")):
                 self.assertEqual(
index 1280ad5..335e0e7 100644 (file)
@@ -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']
index ca53cd6..ef24e83 100644 (file)
@@ -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
index 64eab24..9b8b82c 100644 (file)
@@ -5,6 +5,7 @@ from rest_framework import serializers
 from api.fields import AbsoluteURLField
 from catalogue.models import Book
 from club.models import Membership
+from social.models import UserList
 
 
 class BookLiked(serializers.ReadOnlyField):
@@ -15,9 +16,11 @@ class BookLiked(serializers.ReadOnlyField):
         request = self.context['request']
         if not hasattr(request, 'liked_books'):
             if request.user.is_authenticated:
-                request.liked_books = set(
-                    Book.tagged.with_any(request.user.tag_set.all()).values_list('id', flat=True)
-                )
+                like_list = UserList.get_favorites_list(user=request.user)
+                if like_list is not None:
+                    request.liked_books = [b.id for b in like_list.get_books()]
+                else:
+                    request.liked_books = []
             else:
                 request.liked_books = None
         if request.liked_books is not None:
index 2d35357..ee64ee4 100644 (file)
@@ -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:
index 6c24400..d580aa6 100644 (file)
@@ -18,6 +18,7 @@
     created_at: "1970-01-03 0:0Z"
     changed_at: "1970-01-03 0:0Z"
     extra_info: '{"epoch": "Barok"}'
+    has_audio: true
 - model: catalogue.book
   pk: 2
   fields:
index 7ed0b4c..d09a09a 100644 (file)
@@ -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
 
@@ -806,7 +807,8 @@ class Book(models.Model):
         for format_ in constants.EBOOK_FORMATS_WITH_CHILDREN:
             if format_ not in dont_build:
                 getattr(book, '%s_file' % format_).build_delay()
-        book.html_nonotes_file.build_delay()
+        if 'html_nonotes' not in dont_build:
+            book.html_nonotes_file.build_delay()
 
         if not settings.NO_SEARCH_INDEX and search_index and findable:
             tasks.index_book.delay(book.id)
@@ -815,7 +817,8 @@ class Book(models.Model):
             child.parent_cover_changed()
 
         book.update_popularity()
-        tasks.update_references.delay(book.id)
+        if 'references' not in dont_build:
+            tasks.update_references.delay(book.id)
 
         cls.published.send(sender=cls, instance=book)
         return book
index 4c25b8c..24b2d85 100644 (file)
@@ -26,4 +26,4 @@ class Snippet(models.Model):
 
     @classmethod
     def update_all(cls):
-        cls.objects.all().update(search_vector = build_search_vector('text'))
+        cls.objects.all().update(search_vector=UnaccentSearchVector('text'))
index 4852c9a..27748a6 100644 (file)
@@ -8,6 +8,12 @@
 {% load annoy %}
 
 
+{% block settings %}
+{% load title %}
+{% title book.pretty_title %}
+{% endblock %}
+
+
 {% block global-content %}
 <div class="l-container">
   {% annoy_banner 'book-page' %}
                       <div class="c-media__actions lay-col lay-l-row">
                         <div class="c-media__btn">
                           {% if book.has_audio %}
-                            <button class="l-button l-button--media" id="audiobook"><i class="icon icon-audio"></i> {% trans "pobierz audiobook" %}</button>
+                            <button class="l-button l-button--media l-button--dialog" id="audiobook"><i class="icon icon-audio"></i> {% trans "pobierz audiobook" %}</button>
                           {% endif %}
                         </div>
                         <div class="c-media__btn">
-                          <button class="l-button l-button--media" id="ebook"><i class="icon icon-book"></i> {% trans "pobierz książkę" %}</button>
+                          <button class="l-button l-button--media l-button--dialog" id="ebook"><i class="icon icon-book"></i> {% trans "pobierz książkę" %}</button>
                         </div>
                         <div class="c-media__btn">
                           {% if first_text %}
                   {% endif %}
 
 
-                  <div class="c-media__popup" data-popup="ebook">
-                    <div class="c-media__popup__box">
+                    <dialog class="c-media__popup__box" data-popup="ebook" closedby="any" aria-labelledby="popup-dl-ebook-title">
                       <div class="c-media__popup__box__lead">
-                        <h2>{% trans "Pobieranie e-booka" %}</h2>
+                        <h2 id="popup-dl-ebook-title">{% trans "Pobieranie e-booka" %}</h2>
                         <p>{% trans "Wybierz wersję dla siebie" %}:</p>
                       </div>
                       <div class="c-media__popup__box__items">
                             </div>
                           </div>
                         {% endif %}
-                        {% if book.txt_file or book.fb2_file %}
                           <div class="c-media__popup__box__item">
                             <div>
                               <h3>{% trans "inne formaty" %}</h3>
                               </ul>
                             </div>
                           </div>
-                        {% endif %}
                       </div>
                       <button class="c-media__popup__close">
                         <img src="{% static '2022/images/close.svg' %}" alt="{% trans 'Zamknij' %}">
                       </button>
-                    </div>
-                  </div>
+                  </dialog>
                   {% if book.has_audio %}
-                    <div class="c-media__popup" data-popup="audiobook">
-                      <div class="c-media__popup__box">
+                    <dialog class="c-media__popup__box" data-popup="audiobook" closedby="any" aria-labelledby="popup-dl-audio-title">
                         <div class="c-media__popup__box__lead">
-                          <h2>{% trans "Pobieranie audiobooka" %}</h2>
+                          <h2 id="popup-dl-audio-title">{% trans "Pobieranie audiobooka" %}</h2>
                           <p>{% trans "Wybierz wersję dla siebie" %}:</p>
                         </div>
                         <div class="c-media__popup__box__items">
                         <button class="c-media__popup__close">
                           <img src="{% static '2022/images/close.svg' %}" alt="{% trans 'Zamknij' %}">
                         </button>
-                      </div>
-                    </div>
+                    </dialog>
                   {% endif %}
                 </div>
               {% else %}
index 45805c4..ad0089a 100644 (file)
@@ -9,7 +9,10 @@
 {% load annoy %}
 
 
-{% block title %}{{ book.pretty_title }}{% endblock %}
+{% block settings %}
+{% load title %}
+{% title book.pretty_title %}
+{% endblock %}
 
 
 {% block extrahead %}
index e50ab58..2901975 100644 (file)
@@ -164,7 +164,7 @@ def book_tree_texml(book_list, books_by_parent, depth=1):
             %(children)s
             """ % {
                 "depth": depth,
-                "title": book.title,
+                "title": book.title.replace('&', '&amp;').replace('<', '&lt;'),
                 "audiences": ", ".join(book.audiences_pl()),
                 "audiobook": "audiobook" if book.has_media('mp3') else "",
                 "children": book_tree_texml(books_by_parent.get(book.id, ()), books_by_parent, depth + 1)
index a145522..af3659f 100644 (file)
@@ -13,7 +13,7 @@ from librarian import WLURI
 
 @override_settings(
     MEDIA_ROOT=tempfile.mkdtemp(prefix='djangotest_'),
-    CATALOGUE_DONT_BUILD={'pdf', 'mobi', 'epub', 'txt', 'fb2', 'cover'},
+    CATALOGUE_DONT_BUILD={'pdf', 'mobi', 'epub', 'txt', 'fb2', 'cover', 'html_nonotes', 'references'},
     NO_SEARCH_INDEX=True,
     CELERY_TASK_ALWAYS_EAGER=True,
     CACHES={
@@ -38,7 +38,7 @@ class PersonStub:
 
 
 class BookInfoStub:
-    _empty_fields = ['cover_url', 'variant_of']
+    _empty_fields = ['cover_url', 'variant_of', 'license']
     # allow single definition for multiple-value fields
     _salias = {
         'authors': 'author',
index 8d32e64..b8f42b1 100644 (file)
@@ -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
 
 
index eb14390..792d6c8 100644 (file)
@@ -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')
             })
 
@@ -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:
index 45ca0cc..ae92530 100644 (file)
@@ -4,6 +4,7 @@
 from django.core.files.base import ContentFile
 from catalogue.test_utils import *
 from catalogue.models import Book
+from django.contrib.auth.models import User
 
 
 class DictionaryTests(WLTestCase):
@@ -17,6 +18,9 @@ class DictionaryTests(WLTestCase):
             epoch="X-Epoch",
             **info_args("Default Book")
         )
+        self.user = User.objects.create(username='test')
+        self.user.set_password('test')
+        self.user.save()
 
     def test_book_with_footnote(self):
         book_text = b"""<utwor>
@@ -28,6 +32,7 @@ class DictionaryTests(WLTestCase):
         """
 
         book = Book.from_text_and_meta(ContentFile(book_text), self.book_info)
+        self.client.login(username='test', password='test')
 
         self.assertEqual(
             len(self.client.get('/przypisy/').context['object_list']),
index 81d439d..36221f1 100644 (file)
@@ -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):
index e32dd04..f4c8e3b 100644 (file)
@@ -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):
index c670449..7ac3f8f 100644 (file)
@@ -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
index 6c973eb..393a618 100644 (file)
@@ -46,10 +46,12 @@ class OpdsSearchTests(WLTestCase):
         """Search by author."""
         self.assert_finds('q=fraszka&author=Kochanowski', [self.do_doktora])
         self.assert_finds('q=fraszka+author:Kochanowski', [self.do_doktora])
-        self.assert_finds('q=Kochanowski', [self.do_doktora])
+        # This never worked:
+        #self.assert_finds('q=Kochanowski', [self.do_doktora])
 
     def test_opds_search_translator(self):
         """Search by translator."""
         self.assert_finds('q=fraszka&translator=Fikcyjny', [self.do_doktora])
         self.assert_finds('q=fraszka+translator:Fikcyjny', [self.do_doktora])
-        self.assert_finds('q=Fikcyjny', [self.do_doktora])
+        # This never worked:
+        #self.assert_finds('q=Fikcyjny', [self.do_doktora])
index 561eb99..3862c5c 100644 (file)
@@ -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 = ''
 
@@ -444,8 +444,10 @@ class SearchFeed(AcquisitionFeed):
             ).filter(search_vector=UnaccentSearchQuery(criteria['categories'], config=settings.SEARCH_CONFIG))
             books = books.filter(tag_relations__tag__in=tags)
         if criteria['translator']:
-            # TODO
-            pass
+            authors = Tag.objects.filter(category='author').annotate(
+                search_vector=UnaccentSearchVector('name_pl')
+            ).filter(search_vector=UnaccentSearchQuery(criteria['translator'], config=settings.SEARCH_CONFIG))
+            books = books.filter(translators__in=authors)
         if criteria['title']:
             books = books.filter(
                 search_vector=UnaccentSearchQuery(criteria['title'], config=settings.SEARCH_CONFIG)
index a5e7ebe..cf80b46 100644 (file)
@@ -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,
index 6ec0b80..98a2fac 100644 (file)
@@ -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
index eb64746..22c0e52 100644 (file)
@@ -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"),
     })
 
 
index 77ff1ae..69263e7 100644 (file)
@@ -1,31 +1,10 @@
 from django.conf import settings
-from django.db.models import Func
-from django.contrib.postgres.search import SearchQuery, SearchVectorField
+from django.contrib.postgres.search import SearchQuery, SearchVector
 
 
-class UnaccentSearchQuery(SearchQuery):
-    '''
-    The idea is to run unaccent *after* the query is already passed through the language dictionary.
-    '''
-    def as_sql(self, *args, **kwargs):
-        sql, params = super().as_sql(*args, **kwargs)
-        if settings.SEARCH_USE_UNACCENT:
-            sql = f'unaccent({sql}::text)::tsquery'
-        return sql, params
+# Deprecated
+UnaccentSearchQuery = SearchQuery
 
 
-class UnaccentSearchVector(Func):
-    '''
-    We do the indexing twice, to account for non-diacritic versions.
-    For example: user enters 'róże' -> stem to 'róża' -> unaccent to 'roza'.
-    But user enters 'roze' -> stem leaves it as is, so we need original form in the vector.
-    '''
-    function='to_tsvector'
-    if settings.SEARCH_USE_UNACCENT:
-        template = f'''unaccent(
-        %(function)s('{settings.SEARCH_CONFIG}', %(expressions)s)::text)::tsvector ||
-        to_tsvector(
-        '{settings.SEARCH_CONFIG_SIMPLE}', 
-        unaccent(%(expressions)s)
-        )'''
-    output_field = SearchVectorField()
+def UnaccentSearchVector(expression):
+    return SearchVector(expression, config=settings.SEARCH_CONFIG)
index 6066cd9..6a9e1ea 100644 (file)
@@ -29,7 +29,7 @@ def get_hints(prefix, user=None, limit=10):
     data = []
     if len(data) < limit:
         authors = catalogue.models.Tag.objects.filter(
-            category='author', name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category')
+            category='author', name_pl__iregex=r'\m' + prefix).only('name', 'id', 'slug', 'category')
         data.extend([
             {
                 'type': 'author',
@@ -44,7 +44,7 @@ def get_hints(prefix, user=None, limit=10):
     
     if user is not None and user.is_authenticated and len(data) < limit:
         tags = social.models.UserList.objects.filter(
-            user=user, name__iregex='\m' + prefix).only('name', 'id', 'slug')
+            user=user, name__iregex=r'\m' + prefix).only('name', 'id', 'slug')
         data.extend([
             {
                 'type': 'userlist',
@@ -56,7 +56,7 @@ def get_hints(prefix, user=None, limit=10):
         ])
     if len(data) < limit:
         tags = catalogue.models.Tag.objects.filter(
-            category__in=('theme', 'genre', 'epoch', 'kind'), name_pl__iregex='\m' + prefix).only('name', 'id', 'slug', 'category')
+            category__in=('theme', 'genre', 'epoch', 'kind'), name_pl__iregex=r'\m' + prefix).only('name', 'id', 'slug', 'category')
         data.extend([
             {
                 'type': tag.category,
@@ -69,7 +69,7 @@ def get_hints(prefix, user=None, limit=10):
         ])
     if len(data) < limit:
         collections = catalogue.models.Collection.objects.filter(
-            title_pl__iregex='\m' + prefix).only('title', 'slug')
+            title_pl__iregex=r'\m' + prefix).only('title', 'slug')
         data.extend([
             {
                 'type': 'collection',
@@ -80,7 +80,7 @@ def get_hints(prefix, user=None, limit=10):
             for collection in collections[:limit - len(data)]
         ])
     if len(data) < limit:
-        for b in catalogue.models.Book.objects.filter(findable=True, title__iregex='\m' + prefix)[:limit-len(data)]:
+        for b in catalogue.models.Book.objects.filter(findable=True, title__iregex=r'\m' + prefix)[:limit-len(data)]:
             author_str = b.author_unicode()
             translator = b.translator()
             if translator:
@@ -99,7 +99,7 @@ def get_hints(prefix, user=None, limit=10):
         infos = infopages.models.InfoPage.objects.filter(
             published=True,
             findable=True,
-            title_pl__iregex='\m' + prefix).only('title', 'id', 'slug')
+            title_pl__iregex=r'\m' + prefix).only('title', 'id', 'slug')
         data.extend([
             {
                 'type': 'info',
index 155c0e6..3b581a0 100644 (file)
@@ -154,6 +154,8 @@ class UserListItemReadSerializerV3(UserListItemSerializer):
 class UserListItemReadSerializer(UserListItemSerializer):
     book = catalogue.api.serializers.BookSerializer2()
     bookmark = bookmarks.api.views.BookmarkSerializer()
+    quote = bookmarks.api.views.QuoteSerializer()
+
     class Meta:
         model = models.UserListItem
         fields = [
index 8e09e81..a2d92cc 100644 (file)
@@ -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)
index 45ee0f4..a8bec9c 100644 (file)
@@ -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
index 6447f34..b86e2fd 100644 (file)
@@ -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:
index 80412fc..552fb07 100644 (file)
@@ -76,7 +76,7 @@ class SponsorPage(models.Model):
                     min(THUMB_HEIGHT,
                         round(simg.size[1] * THUMB_WIDTH / simg.size[0]))
                 )
-                simg = simg.resize(size, Image.ANTIALIAS)
+                simg = simg.resize(size, Image.Resampling.LANCZOS)
             sprite.paste(simg, (
                     round((THUMB_WIDTH - simg.size[0]) / 2),
                     round(i * THUMB_HEIGHT + (THUMB_HEIGHT - simg.size[1]) / 2),
index ca0b55d..5dcd551 100644 (file)
@@ -23,7 +23,7 @@ class VisitsBase(models.Model):
         data = urlopen(url).read().decode('utf-16')
         lines = data.split('\n')[1:]
         for line in lines:
-            m = re.match('^/katalog/lektura/([^,]+)\.html,', line)
+            m = re.match(r'^/katalog/lektura/([^,]+)\.html,', line)
             if m is not None:
                 slug = m.group(1)
                 _url, uviews, views, _rest = line.split(',', 3)
index 89e520f..0acfa90 100644 (file)
@@ -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/'
@@ -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',
     },
 }
index 84503ed..86a1a8f 100644 (file)
@@ -4,6 +4,7 @@
 import os
 
 DEBUG = os.environ.get('DEBUG', '')
+SECRET_KEY = os.environ.get('SECRET_KEY', None)
 
 ADMINS = [
     # ('Your Name', 'your_email@domain.com'),
@@ -37,18 +38,30 @@ CACHE_MIDDLEWARE_SECONDS = 3 * 60
 
 CACHES = {
     'default': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
         'TIMEOUT': 180,
         'LOCATION': [
             'memcached:11211',
         ],
+        'OPTIONS': {
+            "no_delay": True,
+            "ignore_exc": True,       # treat memcached errors as cache misses
+            "max_pool_size": 4,
+            "use_pooling": True,
+        },
     },
     'template_fragments': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',
         'TIMEOUT': 86400,
         'LOCATION': [
             'memcached:11211',
         ],
+        'OPTIONS': {
+            "no_delay": True,
+            "ignore_exc": True,       # treat memcached errors as cache misses
+            "max_pool_size": 4,
+            "use_pooling": True,
+        },
     },
 }
 
@@ -105,8 +118,11 @@ MIDDLEWARE = [
     'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
     'django.middleware.cache.FetchFromCacheMiddleware',
     'experiments.middleware.experiments_middleware',
+    "allauth.account.middleware.AccountMiddleware",
 ]
 
 ROOT_URLCONF = 'wolnelektury.urls'
 
 FILE_UPLOAD_PERMISSIONS = 0o640
+
+FORMS_URLFIELD_ASSUME_HTTPS = True
index 65b8200..baeb4e6 100644 (file)
@@ -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')
index b83691b..505d139 100644 (file)
@@ -134,17 +134,24 @@ 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 = ''
+STORAGES = {
+    'default': {
+        'BACKEND': 'django.core.files.storage.FileSystemStorage'
+    },
+    'staticfiles': {
+        'BACKEND': 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage'
+    },
+}
 
 
 STATICFILES_FINDERS = [
index f5d70b2..21a1ba5 100644 (file)
@@ -7,6 +7,7 @@ THUMBNAIL_BACKEND = 'wolnelektury.test_utils.DummyThumbnailBackend'
 CATALOGUE_GET_MP3_LENGTH = 'catalogue.test_utils.get_mp3_length'
 MEDIA_URL = '/media/'
 
-SEARCH_CONFIG = 'english'
-SEARCH_CONFIG_SIMPLE = 'simple'
-SEARCH_USE_UNACCENT = False
+CACHES = {
+    'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
+    'template_fragments': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'},
+}
index 6b15f80..714638e 100644 (file)
   }
 }
 
-.c-media__popup {
-  position: fixed;
-  z-index: 10;
-  top: 0;
-  left: 0;
-  height: 100%;
-  align-items: flex-start;
-  justify-content: center;
-  background-color: rgba($color-black, 0.35);
-  display: none;
-  overflow-y: scroll;
-  padding: 10vh 16px 10px 10px;
-  width: 100%;
-
-  @include rwd($break-flow) {
-      padding: 10vh 40px 40px 40px;
-  }
-  
-  &.is-open {
-    display: flex;
-  }
-}
-
 .c-media__popup__box {
-  background-color: #fff;
-  position: relative;
-  border-radius: 10px;
-  overflow: hidden;
+    padding: 0;
+    border: 0;
+    background: none;
+    border-radius: 10px;
 
-  @include rwd($break-flow) {
-      min-width: 640px;
-  }
+    @include rwd($break-flow) {
+        min-width: 640px;
+    }
+
+    &::backdrop {
+        background-color: rgba($color-black, 0.35);
+    }
 }
 
 .c-media__popup__box__lead {
 }
 
 .c-media__popup__box__items {
+    background: white;
     padding: 16px;
   @include rwd($break-flow) {
       padding: 40px;
 }
 
 .c-media__popup__close {
+    --focus-ring: #fff;
   position: absolute;
   padding: 0;
   border: 0;
index e14adbf..74106ff 100644 (file)
@@ -28,7 +28,6 @@
   padding: 21px;
   box-shadow: 0 4px 10px rgba(0, 0, 0, 0);
   transition: all $ease-dynamic 350ms;
-  outline: 0;
   margin: 5px;
 
   &.l-books__item--placeholder {
     visibility: hidden;
   }
 
-  & * {
-    outline: 0;
-  }
-
   &:hover {
     box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
   }
@@ -55,6 +50,7 @@
     line-height: 140%;
     letter-spacing: -0.01em;
     color: #FFFFFF;
+    --focus-ring: #fff;
 
     display: flex;
     flex-direction: column;
   font-size: 0;
   margin: 0 0 11px;
 
-  img {
-      width: 100%;
+  a {
+      display: block;
+      img {
+          width: 100%;
+      }
   }
 }
 
     border-radius: 52px;
     border: 1px solid #D9D9D9;
     width: 100%;
-    outline: 0;
     transition: border $ease-out 350ms;
 
     @input rwd($break-flow) {
       padding: 0;
       margin: 0 0 0 30px;
       background-color: transparent;
-      outline: 0;
       font-weight: $regular;
       @include font-size(18px);
       line-height: 150%;
index fd4a53a..eddcf33 100644 (file)
@@ -1,4 +1,5 @@
 .l-footer {
+    --focus-ring: #fff;
   color: #FFFFFF;
   background: #083F4D;
   margin: 0 auto;
index 9e3aafc..ece84d5 100644 (file)
@@ -29,24 +29,6 @@ body {
     align-items: center;
     justify-content: space-between;
   }
-
-  &.is-open {
-    position: fixed;
-    top: 0; left: 0;
-    width: 100%;
-    z-index: $master-layer;
-
-    .l-navigation__logo {
-        width: unset;
-        overflow: unset;
-    }
-
-    .l-navigation__menu {
-      opacity: 1;
-      visibility: visible;
-      pointer-events: auto;
-    }
-  }
 }
 
 .l-navigation__logo {
@@ -342,12 +324,8 @@ body:has(dialog[open]) {
       gap: 3%;
   }
 
-  ul {
-    margin: 0;
-    padding: 0;
-    list-style: none;
-    //max-width: 212px;
-    width: 45%;
+  .l-navigation__menu__group {
+      width: 45%;
 
     @include rwd($break-menu) {
       width: 100%;
@@ -355,6 +333,19 @@ body:has(dialog[open]) {
       margin-bottom: 20px;
     }
 
+    h2 {
+        margin: 16px 0 0 0;
+        color: #92BD39;
+        font-weight: $semibold;
+        @include font-size(21px);
+        line-height: 140%;
+        letter-spacing: -0.01em;
+    }
+
+    ul {
+        margin: 0;
+        padding: 0;
+        list-style: none;
     li {
       font-weight: $regular;
       font-size: 16px;
@@ -366,14 +357,6 @@ body:has(dialog[open]) {
           line-height: 115%;
       }
 
-      strong {
-        color: #92BD39;
-        font-weight: $semibold;
-        @include font-size(21px);
-        line-height: 140%;
-        letter-spacing: -0.01em;
-      }
-
       a {
         color: $color-white;
         &:hover {
@@ -395,6 +378,7 @@ body:has(dialog[open]) {
         border: 0;
       }
     }
+    }
   }
 }
 
index fe38f2a..e98c691 100644 (file)
@@ -19,7 +19,6 @@
 }
 
 .l-quotes__item {
-  outline: 0;
   background: #E1F1F2;
   border-radius: 10px;
   width: 558px;
index 98570d4..bab0d0a 100644 (file)
@@ -30,7 +30,6 @@
   }
 
   button {
-    outline: 0;
     width: 40px;
     height: 40px;
     background: transparent;
index b646bf4..5b7f897 100644 (file)
 
 // Ebook/Audiobook Btns
 (function() {
-  let button = $('.c-media__btn button:not(.l-button--media--full)');
-  let popupLayer = $('.c-media__popup');
-  let closeButton = $('.c-media__popup__close');
+    let dialogs = $(".l-button--dialog");
+    dialogs.on('click', function () {
+        let target = $(this).attr('id');
+        $('[data-popup=' + target)[0].showModal();
+    });
+
+    $('.c-media__popup__close').on('click', function() {
+        $(this).closest('dialog')[0].close();
+    });
+})();
+
+
+// Player
+(function() {
   let playButton = $('.c-player__btn--md');
   let chaptersButton = $('.c-player__chapters span');
   let select = $('.c-select');
   let selectItem = $('.c-select li');
   let volumeButton = $('.icon-volume');
 
-  button.on('click', function () {
-    let target = $(this).attr('id');
-    $('[data-popup=' + target).addClass('is-open');
-    $('body').addClass('popup-open');
-  });
-
-  closeButton.on('click', function() {
-    $(this).closest('.c-media__popup').removeClass('is-open');
-    $('body').removeClass('popup-open');
-  });
-
-  popupLayer.on('click', function(e) {
-    let _this = $(this);
-    if($(e.target).is(popupLayer)) {
-      _this.removeClass('is-open');
-      $('body').removeClass('popup-open');
-    }
-  });
-
   chaptersButton.on('click', function() {
     $(this).parent().toggleClass('is-active');
   });
     selectItem.removeClass('is-active');
     $(this).addClass('is-active');
   });
-
-  $(document).keyup(function(e) {
-    if (e.keyCode === 27) {
-      $('.c-media__popup').removeClass('is-open');
-    }
-  });
 })();
 
 // Homepage books sliders
                     updateLiked($btn);
                 },
                 error: function() {
-                    window.location.href = $('#login-link').attr('href');
+                    window.location.href = $('.login-link').attr('href');
                 }
             })
         } else {
                     updateLiked($btn);
                 },
                 error: function() {
-                    window.location.href = $('#login-link').attr('href')
+                    window.location.href = $('.login-link').attr('href')
                 }
             });
         }
diff --git a/src/wolnelektury/templates/account/base.html b/src/wolnelektury/templates/account/base.html
deleted file mode 100644 (file)
index 093fcb2..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-{% extends "base_simple.html" %}
-
-{% block body %}
-  <div class="white-box">
-    {% block content %}{% endblock %}
-  </div>
-{% endblock %}
-
-{% block extrabody %}
-  {% block extra_body %}{% endblock %}
-{% endblock %}
index c23c031..eecf3b2 100644 (file)
@@ -3,7 +3,7 @@
 {% block title %}{{ title }} | Administracja - WolneLektury.pl{% endblock %}
 
 {% block branding %}
-  <h1 id="site-name">Administracja - WolneLektury.pl</h1>
+  <div id="site-name">Administracja - WolneLektury.pl</div>
   <p style="font-size: 11px;margin-top:-6px;">
     <a href="/admin/chunks/chunk/promo/">promobox</a> |
     <a href="/admin/social/cite">bannery</a> |
diff --git a/src/wolnelektury/templates/allauth/layouts/base.html b/src/wolnelektury/templates/allauth/layouts/base.html
new file mode 100644 (file)
index 0000000..093fcb2
--- /dev/null
@@ -0,0 +1,11 @@
+{% extends "base_simple.html" %}
+
+{% block body %}
+  <div class="white-box">
+    {% block content %}{% endblock %}
+  </div>
+{% endblock %}
+
+{% block extrabody %}
+  {% block extra_body %}{% endblock %}
+{% endblock %}
index 7b257b3..9bb3b15 100644 (file)
@@ -17,8 +17,8 @@
       <img src="{% static "2022/images/logo.svg" %}" alt="WolneLektury.pl">
     </a>
     <div class="l-naviagion__search">
-      <form action="/szukaj/">
-        <input id="search" name="q" type="text" placeholder="szukaj tytułu, autora, motywów…" autocomplete="off" data-source="/szukaj/hint/?max=10">
+      <form action="/szukaj/" role="search">
+        <input id="search" name="q" type="text" placeholder="szukaj tytułu, autora, motywów…" autocomplete="off" data-source="/szukaj/hint/?max=10" aria-label="szukaj">
       </form>
     </div>
     <div class="l-navigation__actions">
           <div class="l-navigation__menu__blocks">
             <div class="l-navigation__menu__links">
               {% cache 30 menu LANGUAGE_CODE %}
-                <ul>
-                  <li><strong>{% trans "Katalog" %}</strong></li>
+              <div class="l-navigation__menu__group">
+                <h2 id="menu-group-1">{% trans "Katalog" %}</h2>
+                <ul aria-labelledby="menu-group-1">
                   {% menu 'Katalog' %}
                 </ul>
-                <ul>
-                  <li><strong>{% trans "Włącz się" %}</strong></li>
+              </div>
+              <div class="l-navigation__menu__group">
+                <h2 id="menu-group-2">{% trans "Włącz się" %}</h2>
+                <ul aria-labelledby="menu-group-2">
                   {% menu 'Włącz się' %}
                 </ul>
-                <ul>
-                  <li><strong>{% trans "Aktualności" %}</strong></li>
+              </div>
+              <div class="l-navigation__menu__group">
+                <h2 id="menu-group-3">{% trans "Aktualności" %}</h2>
+                <ul aria-labelledby="menu-group-3">
                   {% latest_blog_posts %}
                   {% menu 'Aktualności' %}
                 </ul>
-                <ul>
-                  <li><strong>{% trans "Narzędzia" %}</strong></li>
+              </div>
+              <div class="l-navigation__menu__group">
+                <h2 id="menu-group-4">{% trans "Narzędzia" %}</h2>
+                <ul aria-labelledby="menu-group-4">
                   {% menu 'Narzędzia' %}
                 </ul>
-                <ul>
-                  <li><strong>{% trans "O nas" %}</strong></li>
+              </div>
+              <div class="l-navigation__menu__group">
+                <h2 id="menu-group-5">{% trans "O nas" %}</h2>
+                <ul aria-labelledby="menu-group-5">
                   {% menu 'O nas' %}
                 </ul>
+              </div>
               {% endcache %}
             </div>
 
               </div>
 
               <div class="l-navigation__menu__social">
-                <ul>
+                <ul aria-label="{% trans "Media społecznościowe" %}">
                   <li>
                     <a href="https://www.facebook.com/wolnelektury/"
                        title="Facebook" target="_blank">
index 86d6eed..fb05a98 100644 (file)
               aria-label="{% trans "Menu konta" %}">
     {% endif %}
     {% if request.user.is_staff %}
-      <img src="{% static '2022/images/icons/user-staff.svg' %}">
+      <img src="{% static '2022/images/icons/user-staff.svg' %}" alt="Użytkownik">
     {% elif request.user.membership %}
-      <img src="{% static '2022/images/icons/user-vip.svg' %}">
+      <img src="{% static '2022/images/icons/user-vip.svg' %}" alt="Użytkownik">
     {% else %}
-      <img src="{% static '2022/images/icons/user.svg' %}">
+      <img src="{% static '2022/images/icons/user.svg' %}" alt="Użytkownik">
       {% endif %}
   {% if hide_menu %}
     </a>
@@ -45,7 +45,7 @@
   {% endif %}
 {% else %}
   <div class="l-navigation__login">
-    <a id="login-link" href='{% url 'login' %}?next={{ request.path }}'>{% trans "Zaloguj się" %}</a>
+    <a class="login-link" href='{% url 'login' %}?next={{ request.path }}'>{% trans "Zaloguj się" %}</a>
     /
     <a href='{% url 'register' %}?next={{ request.path }}'>{% trans "Załóż konto" %}</a>
   </div>
index dfa8522..245c076 100644 (file)
@@ -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,