From 6aab1f0effd33577d3ec04b30e7fabdab7115f72 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 2 Feb 2023 17:19:47 +0800 Subject: [PATCH 01/13] Update testing to accommodate Wagtail 4.2 --- .github/workflows/test.yml | 42 ++++++++++++++++++++++++++++---------- README.md | 2 +- tox.ini | 7 ++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d74141c..80151d68 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,10 +23,10 @@ jobs: with: fetch-depth: 0 - name: Set up Python 3.8 - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: '3.8' - - uses: pre-commit/action@v2.0.3 + - uses: pre-commit/action@v3.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -35,18 +35,26 @@ jobs: needs: lint strategy: matrix: - python: ['3.7', '3.8', '3.9'] + python: ['3.7', '3.8', '3.9', '3.10', '3.11'] django: ['3.2'] - wagtail: ['2.15', '2.16', '3.0', '4.0'] + wagtail: ['2.15', '2.16', '3.0', '4.0', '4.1', '4.2'] include: - - python: '3.9' + - python: '3.10' django: '4.1' wagtail: '4.0' experimental: false + - python: '3.10' + django: '4.1' + wagtail: '4.1' + experimental: false + - python: '3.11' + django: '4.1' + wagtail: '4.2' + experimental: false steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install Tox @@ -70,9 +78,9 @@ jobs: needs: lint strategy: matrix: - python: ['3.7', '3.8', '3.9'] + python: ['3.7', '3.8', '3.9', '3.10', '3.11'] django: ['3.2'] - wagtail: ['2.15', '2.16', '3.0'] + wagtail: ['2.15', '2.16', '3.0', '4.0', '4.1', '4.2'] experimental: [false] include: - python: '3.9' @@ -91,6 +99,18 @@ jobs: django: '4.1' wagtail: '4.0' experimental: false + - python: '3.10' + django: '4.1' + wagtail: '4.0' + experimental: false + - python: '3.10' + django: '4.1' + wagtail: '4.1' + experimental: false + - python: '3.11' + django: '4.1' + wagtail: '4.2' + experimental: false services: postgres: image: ${{ matrix.postgres || 'postgres:11' }} @@ -103,7 +123,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install Tox @@ -132,7 +152,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - name: Install dependencies @@ -144,6 +164,6 @@ jobs: run: | coverage run testmanage.py test - name: 'Upload coverage to Codecov' - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: fail_ci_if_error: true diff --git a/README.md b/README.md index 538fc805..7adc932e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Wagtail Localize requires the following: - Python (3.7, 3.8, 3.9, 3.10, 3.11) - Django (3.2, 4.0, 4.1) -- Wagtail (2.15, 2.16, 3.0, 4.0, 4.1) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) +- Wagtail (2.15, 2.16, 3.0, 4.0, 4.1, 4.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) ## Installation diff --git a/tox.ini b/tox.ini index 37bbe0dd..9ed515b9 100644 --- a/tox.ini +++ b/tox.ini @@ -5,8 +5,8 @@ usedevelop = True envlist = python{3.7,3.8,3.9}-django{3.2}-wagtail{2.15,2.16,3.0,4.0}-{sqlite,postgres} python{3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0,main}-{sqlite,postgres} - python{3.7,3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,4.1,main}-{sqlite,postgres} - python{3.8, 3.9, 3.10, 3.11}-django{4.1,main}-wagtail{4.0,4.1,main}-{sqlite,postgres} + python{3.7,3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,4.1,4.2,main}-{sqlite,postgres} + python{3.8, 3.9, 3.10, 3.11}-django{4.1,main}-wagtail{4.0,4.1,4.2,main}-{sqlite,postgres} [flake8] # E501: Line too long @@ -38,7 +38,8 @@ deps = wagtail2.16: wagtail>=2.16,<2.17 wagtail3.0: wagtail>=3.0,<4.0 wagtail4.0: wagtail>=4.0,<4.1 - wagtail4.1: wagtail>=4.1,<5.0 + wagtail4.1: wagtail>=4.1,<4.2 + wagtail4.2: wagtail>=4.2rc1,<5.0 wagtailmain: git+https://github.com/wagtail/wagtail.git # Pinned to work around UTC connection error From f4d3bae22b4ac024babf9cb5f6ad1440b5d148b1 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 2 Feb 2023 17:25:43 +0800 Subject: [PATCH 02/13] Fixed isort in linter --- .github/workflows/test.yml | 4 ++-- .pre-commit-config.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80151d68..0f2dfa6a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,7 +78,7 @@ jobs: needs: lint strategy: matrix: - python: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python: ['3.7', '3.8', '3.9', '3.10'] django: ['3.2'] wagtail: ['2.15', '2.16', '3.0', '4.0', '4.1', '4.2'] experimental: [false] @@ -107,7 +107,7 @@ jobs: django: '4.1' wagtail: '4.1' experimental: false - - python: '3.11' + - python: '3.10' django: '4.1' wagtail: '4.2' experimental: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d0c5d8f9..42769e69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: - id: black - repo: https://github.com/pycqa/isort # isort config is in setup.cfg - rev: 5.9.3 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/pycqa/flake8 From 2e1928ca733f26fd02b19d110eaddf18672c77e5 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 2 Feb 2023 20:26:15 +0800 Subject: [PATCH 03/13] Updated Changelog, Dropped wagtail 2.16 to 4.0 from test matrix --- .github/workflows/test.yml | 28 ++-------------------------- CHANGELOG.md | 4 ++++ README.md | 2 +- tox.ini | 7 ++----- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f2dfa6a..8fddb540 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,12 +37,8 @@ jobs: matrix: python: ['3.7', '3.8', '3.9', '3.10', '3.11'] django: ['3.2'] - wagtail: ['2.15', '2.16', '3.0', '4.0', '4.1', '4.2'] + wagtail: ['2.15', '4.1', '4.2'] include: - - python: '3.10' - django: '4.1' - wagtail: '4.0' - experimental: false - python: '3.10' django: '4.1' wagtail: '4.1' @@ -80,29 +76,9 @@ jobs: matrix: python: ['3.7', '3.8', '3.9', '3.10'] django: ['3.2'] - wagtail: ['2.15', '2.16', '3.0', '4.0', '4.1', '4.2'] + wagtail: ['2.15', '4.1', '4.2'] experimental: [false] include: - - python: '3.9' - django: '4.0' - wagtail: '2.16' - experimental: false - - python: '3.9' - django: '4.0' - wagtail: '3.0' - experimental: false - - python: '3.9' - django: '4.0' - wagtail: '4.0' - experimental: false - - python: '3.9' - django: '4.1' - wagtail: '4.0' - experimental: false - - python: '3.10' - django: '4.1' - wagtail: '4.0' - experimental: false - python: '3.10' django: '4.1' wagtail: '4.1' diff --git a/CHANGELOG.md b/CHANGELOG.md index b08800f2..e0f96383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Added tests for Wagtail 4.2 and dropped tests with Wagtail versions 2.16 to 4.0 from the workflow - [#673](https://github.com/wagtail/wagtail-localize/pull/673) @katdom13 + ## [1.4] - 2023-01-22 ### Added diff --git a/README.md b/README.md index 7adc932e..ab300567 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Wagtail Localize requires the following: - Python (3.7, 3.8, 3.9, 3.10, 3.11) - Django (3.2, 4.0, 4.1) -- Wagtail (2.15, 2.16, 3.0, 4.0, 4.1, 4.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) +- Wagtail (2.15, 4.1, 4.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) ## Installation diff --git a/tox.ini b/tox.ini index 9ed515b9..33f5d90c 100644 --- a/tox.ini +++ b/tox.ini @@ -5,8 +5,8 @@ usedevelop = True envlist = python{3.7,3.8,3.9}-django{3.2}-wagtail{2.15,2.16,3.0,4.0}-{sqlite,postgres} python{3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0,main}-{sqlite,postgres} - python{3.7,3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0,4.1,4.2,main}-{sqlite,postgres} - python{3.8, 3.9, 3.10, 3.11}-django{4.1,main}-wagtail{4.0,4.1,4.2,main}-{sqlite,postgres} + python{3.7,3.8,3.9,3.10}-django{3.2,4.0}-wagtail{2.15,4.1,4.2,main}-{sqlite,postgres} + python{3.8,3.9,3.10,3.11}-django{4.1,main}-wagtail{4.1,4.2,main}-{sqlite,postgres} [flake8] # E501: Line too long @@ -35,9 +35,6 @@ deps = djangomain: git+https://github.com/django/django.git@main#egg=Django wagtail2.15: wagtail>=2.15,<2.16 - wagtail2.16: wagtail>=2.16,<2.17 - wagtail3.0: wagtail>=3.0,<4.0 - wagtail4.0: wagtail>=4.0,<4.1 wagtail4.1: wagtail>=4.1,<4.2 wagtail4.2: wagtail>=4.2rc1,<5.0 wagtailmain: git+https://github.com/wagtail/wagtail.git From 34430a8e4a2d6289b8e5c3b1d484ba3fe0344004 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Mon, 6 Feb 2023 11:03:38 +0800 Subject: [PATCH 04/13] Removed support for Wagtail < 4.1, Updated documentation --- .github/workflows/test.yml | 29 +++++++++++++++-------------- CHANGELOG.md | 6 +++++- README.md | 6 +++--- pyproject.toml | 4 +--- tox.ini | 9 +++------ 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8fddb540..ad5f47da 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,16 +35,17 @@ jobs: needs: lint strategy: matrix: - python: ['3.7', '3.8', '3.9', '3.10', '3.11'] - django: ['3.2'] - wagtail: ['2.15', '4.1', '4.2'] + python: ['3.8', '3.9', '3.10', '3.11'] + django: ['3.2', '4.0', '4.1'] + wagtail: ['4.1', '4.2'] + experimental: [false] include: - - python: '3.10' - django: '4.1' + - python: '3.7' + django: '3.2' wagtail: '4.1' experimental: false - - python: '3.11' - django: '4.1' + - python: '3.7' + django: '3.2' wagtail: '4.2' experimental: false steps: @@ -74,17 +75,17 @@ jobs: needs: lint strategy: matrix: - python: ['3.7', '3.8', '3.9', '3.10'] - django: ['3.2'] - wagtail: ['2.15', '4.1', '4.2'] + python: ['3.8', '3.9', '3.10', '3.11'] + django: ['3.2', '4.0', '4.1'] + wagtail: ['4.1', '4.2'] experimental: [false] include: - - python: '3.10' - django: '4.1' + - python: '3.7' + django: '3.2' wagtail: '4.1' experimental: false - - python: '3.10' - django: '4.1' + - python: '3.7' + django: '3.2' wagtail: '4.2' experimental: false services: diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f96383..2b08eb2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Added tests for Wagtail 4.2 and dropped tests with Wagtail versions 2.16 to 4.0 from the workflow - [#673](https://github.com/wagtail/wagtail-localize/pull/673) @katdom13 +- [Updated tests to include Wagtail 4.2](https://github.com/wagtail/wagtail-localize/pull/673) @katdom13 + +### Removed + +- [Support for Wagtail < 4.1](https://github.com/wagtail/wagtail-localize/pull/673) @katdom13 ## [1.4] - 2023-01-22 diff --git a/README.md b/README.md index ab300567..c46e3149 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Wagtail Localize requires the following: - Python (3.7, 3.8, 3.9, 3.10, 3.11) - Django (3.2, 4.0, 4.1) -- Wagtail (2.15, 4.1, 4.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) +- Wagtail (4.1, 4.2) with [internationalisation enabled](https://docs.wagtail.org/en/stable/advanced_topics/i18n.html#configuration) ## Installation @@ -100,8 +100,8 @@ Now you can run tests as shown below: tox ``` -or, you can run them for a specific environment `tox -e python3.8-django3.2-wagtail2.15` or specific test -`tox -e python3.9-django3.2-wagtail2.15-sqlite wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView` +or, you can run them for a specific environment `tox -e python3.8-django3.2-wagtail4.1` or specific test +`tox -e python3.9-django3.2-wagtail4.1-sqlite wagtail_localize.tests.test_edit_translation.TestGetEditTranslationView` To run the test app interactively, use `tox -e interactive`, visit `http://127.0.0.1:8020/admin/` and log in with `admin`/`changeme`. diff --git a/pyproject.toml b/pyproject.toml index 3180acb4..af35b317 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,15 +25,13 @@ classifiers = [ "Framework :: Django :: 4.0", "Framework :: Django :: 4.1", "Framework :: Wagtail", - "Framework :: Wagtail :: 2", - "Framework :: Wagtail :: 3", "Framework :: Wagtail :: 4" ] dynamic = ["version"] requires-python = ">=3.7" dependencies = [ "Django>=3.2,<4.2", - "Wagtail>=2.15,<5.0", + "Wagtail>=4.1,<5.0", "polib>=1.1,<2.0", "typing_extensions>=4.0" ] diff --git a/tox.ini b/tox.ini index 33f5d90c..d6d73a60 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,8 @@ skipsdist = True usedevelop = True envlist = - python{3.7,3.8,3.9}-django{3.2}-wagtail{2.15,2.16,3.0,4.0}-{sqlite,postgres} - python{3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0,main}-{sqlite,postgres} - python{3.7,3.8,3.9,3.10}-django{3.2,4.0}-wagtail{2.15,4.1,4.2,main}-{sqlite,postgres} - python{3.8,3.9,3.10,3.11}-django{4.1,main}-wagtail{4.1,4.2,main}-{sqlite,postgres} + python{3.7}-django{3.2}-wagtail{4.1,4.2,main}-{sqlite,postgres} + python{3.8,3.9,3.10,3.11}-django{3.2,4.0,4.1,main}-wagtail{4.1,4.2,main}-{sqlite,postgres} [flake8] # E501: Line too long @@ -34,7 +32,6 @@ deps = django4.1: Django~=4.1 djangomain: git+https://github.com/django/django.git@main#egg=Django - wagtail2.15: wagtail>=2.15,<2.16 wagtail4.1: wagtail>=4.1,<4.2 wagtail4.2: wagtail>=4.2rc1,<5.0 wagtailmain: git+https://github.com/wagtail/wagtail.git @@ -73,7 +70,7 @@ basepython = python3.9 # always generate with the min supported versions deps = Django~=3.2 - wagtail>=2.15,<2.16 + wagtail>=4.1 commands = python {toxinidir}/testmanage.py makemigrations From f21976615732d94b6e653b582ac77fe2ac587fb2 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Mon, 6 Feb 2023 18:11:42 +0800 Subject: [PATCH 05/13] Fixed test matrix --- .github/workflows/test.yml | 63 +++++++++++++++++++++++++++++++++++--- tox.ini | 12 ++++++-- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad5f47da..42290615 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,22 +75,75 @@ jobs: needs: lint strategy: matrix: - python: ['3.8', '3.9', '3.10', '3.11'] - django: ['3.2', '4.0', '4.1'] + python: ['3.8', '3.9', '3.10'] + django: ['4.0', '4.1'] wagtail: ['4.1', '4.2'] + postgres: ['15'] experimental: [false] include: - python: '3.7' django: '3.2' wagtail: '4.1' + postgres: '12' experimental: false - python: '3.7' django: '3.2' wagtail: '4.2' + postgres: '12' + experimental: false + - python: '3.8' + django: '3.2' + wagtail: '4.1' + postgres: '12' + experimental: false + - python: '3.8' + django: '3.2' + wagtail: '4.2' + postgres: '12' + experimental: false + - python: '3.9' + django: '3.2' + wagtail: '4.1' + postgres: '12' + experimental: false + - python: '3.9' + django: '3.2' + wagtail: '4.2' + postgres: '12' + experimental: false + - python: '3.10' + django: '3.2' + wagtail: '4.1' + postgres: '12' + experimental: false + - python: '3.10' + django: '3.2' + wagtail: '4.2' + postgres: '12' + experimental: false + - python: '3.11' + django: '4.0' + wagtail: '4.1' + postgres: '15' + experimental: false + - python: '3.11' + django: '4.0' + wagtail: '4.2' + postgres: '15' + experimental: false + - python: '3.11' + django: '4.1' + wagtail: '4.1' + postgres: '15' + experimental: false + - python: '3.11' + django: '4.1' + wagtail: '4.2' + postgres: '15' experimental: false services: postgres: - image: ${{ matrix.postgres || 'postgres:11' }} + image: postgres:${{ matrix.postgres }} env: POSTGRES_PASSWORD: postgres ports: @@ -111,13 +164,13 @@ jobs: uses: actions/cache@v3 with: path: .tox - key: tox-${{ hashFiles('pyproject.toml') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-postgres + key: tox-${{ hashFiles('pyproject.toml') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-postgres${{ matrix.postgres }} - name: Test run: | tox env: DATABASE_URL: postgres://postgres:postgres@localhost:5432/wagtail_localize - TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-postgres + TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-postgres${{ matrix.postgres }} coverage: runs-on: ubuntu-latest diff --git a/tox.ini b/tox.ini index d6d73a60..9efda7f1 100644 --- a/tox.ini +++ b/tox.ini @@ -3,8 +3,11 @@ skipsdist = True usedevelop = True envlist = - python{3.7}-django{3.2}-wagtail{4.1,4.2,main}-{sqlite,postgres} - python{3.8,3.9,3.10,3.11}-django{3.2,4.0,4.1,main}-wagtail{4.1,4.2,main}-{sqlite,postgres} + python{3.7}-django{3.2}-wagtail{4.1,4.2,main}-{sqlite,postgres12} + python{3.8,3.9,3.10,3.11}-django{3.2,4.0,4.1,main}-wagtail{4.1,4.2,main}-sqlite + python{3.8,3.9,3.10}-wagtail{4.1,4.2,main}-{sqlite,postgres12,postgres15} + python{3.8,3.9,3.10}-wagtail{3.2}-postgres12 + python{3.11}-wagtail{4.1,4.2,main}-postgres15 [flake8] # E501: Line too long @@ -38,7 +41,10 @@ deps = # Pinned to work around UTC connection error # https://stackoverflow.com/questions/68024060/assertionerror-database-connection-isnt-set-to-utc - postgres: psycopg2==2.8.6 + postgres12: psycopg2==2.8.6 + + # https://www.psycopg.org/docs/index.html + postgres15: psycopg2==2.9.5 setenv = postgres: DATABASE_URL={env:DATABASE_URL:postgres:///wagtail_localize} From cf763e125edde49077ea362f60cedd9cc7fcb72c Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Mon, 6 Feb 2023 19:56:16 +0800 Subject: [PATCH 06/13] Code cleanup Revert "Code cleanup" This reverts commit 4262d820a9fd292ddba6ee901de84468ad20d470. Code cleanup --- docs/tutorial/3-content.md | 15 +- wagtail_localize/compat.py | 44 +--- wagtail_localize/components.py | 20 +- wagtail_localize/fields.py | 10 +- wagtail_localize/migrations/0001_initial.py | 62 +++-- .../modeladmin/translatable_create.html | 2 +- wagtail_localize/models.py | 29 +-- wagtail_localize/segments/extract.py | 7 +- wagtail_localize/segments/ingest.py | 22 +- .../segments/tests/test_segment_extraction.py | 25 -- .../segments/tests/test_segment_ingestion.py | 4 - wagtail_localize/side_panels.py | 20 +- .../admin/update_translations.html | 2 +- .../test/migrations/0001_initial.py | 7 +- wagtail_localize/test/models.py | 12 +- .../tests/test_edit_translation.py | 38 +--- wagtail_localize/tests/utils.py | 11 +- wagtail_localize/views/convert.py | 11 +- wagtail_localize/views/edit_translation.py | 214 ++++++------------ wagtail_localize/wagtail_hooks.py | 32 +-- 20 files changed, 163 insertions(+), 424 deletions(-) diff --git a/docs/tutorial/3-content.md b/docs/tutorial/3-content.md index f89667d2..f8cf6a1e 100644 --- a/docs/tutorial/3-content.md +++ b/docs/tutorial/3-content.md @@ -34,20 +34,15 @@ Now, open `blog/models.py` and copy and paste the following code into it: ```python from django.db import models -from wagtail import VERSION as WAGTAIL_VERSION -from wagtail.core import blocks -from wagtail.core.fields import StreamField -from wagtail.core.models import Page, TranslatableMixin +from wagtail import blocks +from wagtail.admin.panels import FieldPanel +from wagtail.fields import StreamField +from wagtail.models import Page, TranslatableMixin from wagtail.images.blocks import ImageChooserBlock from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.snippets.edit_handlers import SnippetChooserPanel from wagtail.snippets.models import register_snippet -if WAGTAIL_VERSION >= (3, 0): - from wagtail.admin.panels import FieldPanel -else: - from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel - class ImageBlock(blocks.StructBlock): image = ImageChooserBlock() @@ -84,7 +79,7 @@ class BlogPostPage(Page): content_panels = Page.content_panels + [ FieldPanel("publication_date"), ImageChooserPanel("image"), - FieldPanel("body") if WAGTAIL_VERSION >= (3, 0) else StreamFieldPanel("body"), + FieldPanel("body"), SnippetChooserPanel("category"), ] diff --git a/wagtail_localize/compat.py b/wagtail_localize/compat.py index c2e7ef14..b16bd297 100644 --- a/wagtail_localize/compat.py +++ b/wagtail_localize/compat.py @@ -2,7 +2,6 @@ from django.contrib.admin.utils import quote from django.urls import reverse -from wagtail import VERSION as WAGTAIL_VERSION if os.name == "nt": @@ -14,55 +13,28 @@ def get_snippet_list_url(snippet): - if WAGTAIL_VERSION >= (4, 0): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:list" - ) - - reverse( - "wagtailsnippets:list", args=[snippet._meta.app_label, snippet._meta.model_name] + return reverse( + f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:list" ) def get_snippet_edit_url(snippet): - if WAGTAIL_VERSION >= (4, 0): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:edit", - args=[quote(snippet.pk)], - ) - return reverse( - "wagtailsnippets:edit", - args=[snippet._meta.app_label, snippet._meta.model_name, quote(snippet.pk)], + f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:edit", + args=[quote(snippet.pk)], ) def get_snippet_edit_url_from_args(app_label, model_name, pk): - if WAGTAIL_VERSION >= (4, 0): - return reverse( - f"wagtailsnippets_{app_label}_{model_name}:edit", args=[quote(pk)] - ) - - return reverse( - "wagtailsnippets:edit", - args=[app_label, model_name, quote(pk)], - ) + return reverse(f"wagtailsnippets_{app_label}_{model_name}:edit", args=[quote(pk)]) def get_snippet_delete_url(snippet): - if WAGTAIL_VERSION >= (4, 0): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:delete", - args=[quote(snippet.pk)], - ) - return reverse( - "wagtailsnippets:delete", - args=[snippet._meta.app_label, snippet._meta.model_name, quote(snippet.pk)], + f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:delete", + args=[quote(snippet.pk)], ) def get_revision_model(): - if WAGTAIL_VERSION >= (4, 0): - return "wagtailcore.Revision" - return "wagtailcore.PageRevision" + return "wagtailcore.Revision" diff --git a/wagtail_localize/components.py b/wagtail_localize/components.py index b6491640..157bdc7b 100644 --- a/wagtail_localize/components.py +++ b/wagtail_localize/components.py @@ -3,21 +3,10 @@ from django import forms from django.utils.translation import gettext_lazy as _ -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.forms import WagtailAdminModelForm +from wagtail.admin.panels import ObjectList, extract_panel_definitions_from_model_class -try: - from wagtail.admin.panels import ( - ObjectList, - extract_panel_definitions_from_model_class, - ) -except ImportError: - from wagtail.admin.edit_handlers import ( - ObjectList, - extract_panel_definitions_from_model_class, - ) - TRANSLATION_COMPONENTS = [] @@ -83,13 +72,8 @@ def from_request(cls, request, source_object_instance=None): component_model, source_object_instance=source_object_instance ) edit_handler = cls.get_component_edit_handler(component_model) + edit_handler = edit_handler.bind_to_model(component_model) - if WAGTAIL_VERSION >= (3, 0): - edit_handler = edit_handler.bind_to_model(component_model) - else: - edit_handler = edit_handler.bind_to( - model=component_model, instance=component_instance, request=request - ) form_class = edit_handler.get_form_class() # Add an 'enabled' field to the form if it isn't required diff --git a/wagtail_localize/fields.py b/wagtail_localize/fields.py index d8dd00cc..9df48589 100644 --- a/wagtail_localize/fields.py +++ b/wagtail_localize/fields.py @@ -2,14 +2,8 @@ from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel, get_all_child_relations from treebeard.mp_tree import MP_Node -from wagtail.core.fields import RichTextField, StreamField -from wagtail.core.models import Page, TranslatableMixin - - -try: - from wagtail.core.models import COMMENTS_RELATION_NAME -except ImportError: - COMMENTS_RELATION_NAME = "comments" +from wagtail.fields import RichTextField, StreamField +from wagtail.models import COMMENTS_RELATION_NAME, Page, TranslatableMixin class BaseTranslatableField: diff --git a/wagtail_localize/migrations/0001_initial.py b/wagtail_localize/migrations/0001_initial.py index 09a03a36..f171d4ab 100644 --- a/wagtail_localize/migrations/0001_initial.py +++ b/wagtail_localize/migrations/0001_initial.py @@ -4,7 +4,6 @@ from django.db import migrations, models from django.db.migrations.recorder import MigrationRecorder -from wagtail import VERSION as WAGTAIL_VERSION def get_run_before_and_revision_model(): @@ -12,44 +11,43 @@ def get_run_before_and_revision_model(): run_before = [] revision_model = "wagtailcore.PageRevision" - if WAGTAIL_VERSION >= (4, 0, 0): - # The return value of this function is used in the Migration class - # definition, so everything in this check happens at module load time - # (i.e. at the start of the `migrate` command). + # The return value of this function is used in the Migration class + # definition, so everything in this check happens at module load time + # (i.e. at the start of the `migrate` command). - # Changing the core migration dependency potentially breaks existing - # users as it can cause an InconsistentMigrationHistory error. + # Changing the core migration dependency potentially breaks existing + # users as it can cause an InconsistentMigrationHistory error. - # Based on the dependencies, this migration can be run both before or - # after the PageRevision model is renamed to Revision. As a result, - # we cannot accurately determine the revision_model to use. + # Based on the dependencies, this migration can be run both before or + # after the PageRevision model is renamed to Revision. As a result, + # we cannot accurately determine the revision_model to use. - # What we can do instead is keep pointing to the old PageRevision name, - # but use run_before to make sure that this migration is run before the - # core migration that renames the PageRevision model. - run_before = [("wagtailcore", "0070_rename_pagerevision_revision")] + # What we can do instead is keep pointing to the old PageRevision name, + # but use run_before to make sure that this migration is run before the + # core migration that renames the PageRevision model. + run_before = [("wagtailcore", "0070_rename_pagerevision_revision")] - try: - if MigrationRecorder.Migration.objects.filter( - app="wagtailcore", name="0070_rename_pagerevision_revision" - ).exists(): - # However, if the core migration has already been applied in a - # previous `migrate` run, we should unset run_before to avoid an - # InconsistentMigrationHistory error. + try: + if MigrationRecorder.Migration.objects.filter( + app="wagtailcore", name="0070_rename_pagerevision_revision" + ).exists(): + # However, if the core migration has already been applied in a + # previous `migrate` run, we should unset run_before to avoid an + # InconsistentMigrationHistory error. - # This might be the case if the core migration was run - # separately and an earlier version of wagtail-localize were - # already installed where we did not ensure this migration was - # run before the core migration. - run_before = [] + # This might be the case if the core migration was run + # separately and an earlier version of wagtail-localize were + # already installed where we did not ensure this migration was + # run before the core migration. + run_before = [] - # In any case, it should be safe to point to the new Revision - # model name as the core migration has already been applied. - revision_model = "wagtailcore.Revision" + # In any case, it should be safe to point to the new Revision + # model name as the core migration has already been applied. + revision_model = "wagtailcore.Revision" - except (django.db.utils.OperationalError, django.db.utils.ProgrammingError): - # Normally happens when running tests. - pass + except (django.db.utils.OperationalError, django.db.utils.ProgrammingError): + # Normally happens when running tests. + pass return run_before, revision_model diff --git a/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_create.html b/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_create.html index 50f32259..14d73f29 100644 --- a/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_create.html +++ b/wagtail_localize/modeladmin/templates/wagtail_localize/modeladmin/translatable_create.html @@ -3,4 +3,4 @@ {% block header %} {% include "wagtailadmin/shared/header_with_locale_selector.html" with title=view.get_page_title subtitle=view.get_page_subtitle icon=view.header_icon tabbed=1 merged=1 %} {% endblock %} -{% block form_action %}{{ view.create_url }}{% if wagtail_version < "3.0" %}?locale={{ locale.language_code }}{% endif %}{% endblock %} +{% block form_action %}{{ view.create_url }}{% endblock %} diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index 835c0d49..833dd278 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -36,7 +36,7 @@ get_serializable_data_for_fields, model_from_serializable_data, ) -from wagtail import VERSION as WAGTAIL_VERSION +from wagtail.blocks.list_block import ListValue from wagtail.core import blocks from wagtail.core.fields import StreamField from wagtail.core.models import ( @@ -64,14 +64,6 @@ from .tasks import background -if WAGTAIL_VERSION >= (2, 16): - # Only use in a 2.16+ context - try: - from wagtail.blocks.list_block import ListValue - except ImportError: - from wagtail.core.blocks.list_block import ListValue - - def pk(obj): """ A helper that gets the primary key of a model instance if one is passed in. @@ -526,10 +518,8 @@ def as_instance(self): raise SourceDeletedError if isinstance(instance, Page): - content_json = self.content_json - if WAGTAIL_VERSION >= (3, 0): - # see https://github.com/wagtail/wagtail/pull/8024 - content_json = json.loads(content_json) + # see https://github.com/wagtail/wagtail/pull/8024 + content_json = json.loads(self.content_json) return instance.with_content_json(content_json) elif isinstance(instance, ClusterableModel): @@ -1516,14 +1506,13 @@ def get_field_path_from_streamfield_block(value, path_components): if isinstance(value, blocks.StructValue): blocks_by_id = dict(value) else: - if WAGTAIL_VERSION >= (2, 16) and isinstance( - value, ListValue - ): + if isinstance(value, ListValue): blocks_by_id = { block.id: block for block in value.bound_blocks } else: blocks_by_id = {block.id: block for block in value} + block_id = path_components[0] block = blocks_by_id[block_id] @@ -1532,9 +1521,7 @@ def get_field_path_from_streamfield_block(value, path_components): block_def = value.block.child_blocks[block_type] block_value = block else: - if WAGTAIL_VERSION >= (2, 16) and isinstance( - value, ListValue - ): + if isinstance(value, ListValue): block_type = "item" block_def = value.list_block.child_block else: @@ -1551,9 +1538,7 @@ def get_field_path_from_streamfield_block(value, path_components): return [block_type] + get_field_path_from_streamfield_block( block_value, path_components[1:] ) - elif isinstance( - block_def, blocks.ListBlock - ) and WAGTAIL_VERSION >= (2, 16): + elif isinstance(block_def, blocks.ListBlock): return [block_type] + get_field_path_from_streamfield_block( block_value, path_components[1:] ) diff --git a/wagtail_localize/segments/extract.py b/wagtail_localize/segments/extract.py index c3eaaf7f..0999b8e1 100644 --- a/wagtail_localize/segments/extract.py +++ b/wagtail_localize/segments/extract.py @@ -2,7 +2,6 @@ from django.core.exceptions import ImproperlyConfigured from django.db import models from modelcluster.fields import ParentalKey -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core import blocks from wagtail.core.fields import RichTextField, StreamField from wagtail.core.models import Page, TranslatableMixin @@ -142,7 +141,7 @@ def handle_struct_block(self, struct_block, raw_value=None): def handle_list_block(self, list_block, raw_value=None): segments = [] - if WAGTAIL_VERSION >= (2, 16) and raw_value is not None: + if raw_value is not None: # Wagtail 2.16 changes ListBlock values to be ListValue objects (i.e. {'value': '', 'id': ''}) # and will automatically convert from the simple list format used before. However that requires # the block to be saved. bound_blocks will return ListValue objects, so we need to check that the @@ -186,9 +185,7 @@ def handle_stream_block(self, stream_block): segments = [] for index, block in enumerate(stream_block): - raw_data = ( - stream_block.raw_data[index] if WAGTAIL_VERSION >= (2, 16) else None - ) + raw_data = stream_block.raw_data[index] segments.extend( segment.wrap(block.id) for segment in self.handle_block( diff --git a/wagtail_localize/segments/ingest.py b/wagtail_localize/segments/ingest.py index 99dd2aa8..6bb22ab0 100644 --- a/wagtail_localize/segments/ingest.py +++ b/wagtail_localize/segments/ingest.py @@ -2,7 +2,6 @@ from django.apps import apps from django.db import models -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core import blocks from wagtail.core.fields import RichTextField, StreamField from wagtail.core.rich_text import RichText @@ -203,20 +202,19 @@ def handle_struct_block(self, struct_block, segments): return struct_block def handle_list_block(self, list_block, segments): - if WAGTAIL_VERSION >= (2, 16): - segments_by_block = defaultdict(list) + segments_by_block = defaultdict(list) - for segment in segments: - block_uuid, segment = segment.unwrap() - segments_by_block[block_uuid].append(segment) + for segment in segments: + block_uuid, segment = segment.unwrap() + segments_by_block[block_uuid].append(segment) - for block_index, block in enumerate(list_block.bound_blocks): - block_segments = segments_by_block[block.id] - list_block.bound_blocks[block_index].value = self.handle_block( - block.block, block.value, block_segments - ) + for block_index, block in enumerate(list_block.bound_blocks): + block_segments = segments_by_block[block.id] + list_block.bound_blocks[block_index].value = self.handle_block( + block.block, block.value, block_segments + ) - return list_block + return list_block def get_stream_block_child_data(self, stream_block, block_uuid): for stream_child in stream_block: diff --git a/wagtail_localize/segments/tests/test_segment_extraction.py b/wagtail_localize/segments/tests/test_segment_extraction.py index 9cdf0604..11a3ef6f 100644 --- a/wagtail_localize/segments/tests/test_segment_extraction.py +++ b/wagtail_localize/segments/tests/test_segment_extraction.py @@ -3,7 +3,6 @@ from django.core.exceptions import ImproperlyConfigured from django.test import TestCase -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core.blocks import StreamValue from wagtail.core.models import Page, Site @@ -344,10 +343,6 @@ def test_structblock(self): ], ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_listblock(self): block_id = uuid.uuid4() page = make_test_page_with_streamfield_block( @@ -374,10 +369,6 @@ def test_listblock(self): segments = extract_segments(page) self.assertEqual(segments, expected_segments) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_listblock_not_extracted_when_not_in_block_format(self): page = make_test_page_with_streamfield_block( uuid.uuid4(), "test_listblock", ["Test content", "Some more test content"] @@ -387,10 +378,6 @@ def test_listblock_not_extracted_when_not_in_block_format(self): ).handle_stream_block(page.test_streamfield) self.assertEqual(segments, []) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_listblock_in_structblock(self): block_id = uuid.uuid4() item_one_id = "11111111-1111-1111-1111-111111111111" @@ -429,10 +416,6 @@ def test_listblock_in_structblock(self): self.assertEqual(segments, expected_segments) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_listblock_in_listblock(self): block_id = uuid.uuid4() item_one_id = "11111111-1111-1111-1111-111111111111" @@ -470,10 +453,6 @@ def test_listblock_in_listblock(self): self.assertEqual(segments, expected_segments) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_listblock_in_nestedstreamblock(self): block_id = uuid.uuid4() nested_block_id = uuid.uuid4() @@ -507,10 +486,6 @@ def test_listblock_in_nestedstreamblock(self): ], ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_list_block_empty_should_not_raise_error(self): page = make_test_page_with_streamfield_block(uuid.uuid4(), "test_listblock", []) segments = StreamFieldSegmentExtractor( diff --git a/wagtail_localize/segments/tests/test_segment_ingestion.py b/wagtail_localize/segments/tests/test_segment_ingestion.py index 534d5fbf..b416b7b6 100644 --- a/wagtail_localize/segments/tests/test_segment_ingestion.py +++ b/wagtail_localize/segments/tests/test_segment_ingestion.py @@ -2,7 +2,6 @@ import uuid from django.test import TestCase -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core.blocks import StreamValue from wagtail.core.models import Locale, Page @@ -557,9 +556,6 @@ def test_structblock(self): ], ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), "ListBlocks are supported starting Wagtail 2.16" - ) def test_listblock(self): block_id = uuid.uuid4() page = make_test_page_with_streamfield_block( diff --git a/wagtail_localize/side_panels.py b/wagtail_localize/side_panels.py index 16fc6a8e..de7c19de 100644 --- a/wagtail_localize/side_panels.py +++ b/wagtail_localize/side_panels.py @@ -1,5 +1,4 @@ from django.urls import reverse -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.ui.side_panels import PagePreviewSidePanel, PageSidePanels from wagtail.models import PreviewableMixin @@ -40,18 +39,13 @@ def get_context_data(self, parent_context): class LocalizedPageSidePanels(PageSidePanels): def __init__(self, request, page, translation): - if WAGTAIL_VERSION >= (4, 1): - super().__init__( - request, - page, - preview_enabled=False, - comments_enabled=False, - show_schedule_publishing_toggle=False, - ) - else: - super().__init__( - request, page, preview_enabled=False, comments_enabled=False - ) + super().__init__( + request, + page, + preview_enabled=False, + comments_enabled=False, + show_schedule_publishing_toggle=False, + ) # FIXME: enable the preview panels, with an updated JS handler, as preview-panels.js expects a regular form # self.side_panels += [ diff --git a/wagtail_localize/templates/wagtail_localize/admin/update_translations.html b/wagtail_localize/templates/wagtail_localize/admin/update_translations.html index dc1cb186..fa3c0365 100644 --- a/wagtail_localize/templates/wagtail_localize/admin/update_translations.html +++ b/wagtail_localize/templates/wagtail_localize/admin/update_translations.html @@ -7,7 +7,7 @@
- {% if wagtail_version >= "3.0" %}{% icon name="help" %}{% endif %} + {% icon name="help" %}

{% trans "Why would I sync my page?" %}

{% trans "Changes are not automatically applied between translated pages. Syncing will add new content for translation and remove deleted content." %}

diff --git a/wagtail_localize/test/migrations/0001_initial.py b/wagtail_localize/test/migrations/0001_initial.py index d9b40e66..db97db68 100644 --- a/wagtail_localize/test/migrations/0001_initial.py +++ b/wagtail_localize/test/migrations/0001_initial.py @@ -4,7 +4,6 @@ import django.db.models.deletion import modelcluster.fields import uuid -from wagtail import VERSION as WAGTAIL_VERSION import wagtail.core.blocks import wagtail.core.blocks.field_block import wagtail.core.fields @@ -19,11 +18,7 @@ class Migration(migrations.Migration): initial = True - core_migration = ( - "0076_modellogentry_revision" - if WAGTAIL_VERSION >= (4, 0) - else "0059_apply_collection_ordering" - ) + core_migration = "0076_modellogentry_revision" dependencies = [ ("wagtailcore", "0059_apply_collection_ordering"), ("wagtaildocs", "0010_document_file_hash"), diff --git a/wagtail_localize/test/models.py b/wagtail_localize/test/models.py index 31aa0214..2db5ed75 100644 --- a/wagtail_localize/test/models.py +++ b/wagtail_localize/test/models.py @@ -4,13 +4,11 @@ from django.utils.translation import gettext_lazy from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.edit_handlers import ( FieldPanel, InlinePanel, ObjectList, PageChooserPanel, - StreamFieldPanel, TabbedInterface, ) from wagtail.core import blocks, telepath @@ -236,7 +234,7 @@ def get_translatable_segments(self, value): return [StringSegmentValue("foo", "{} and some extra".format(value))] -SF_KWARGS = {"use_json_field": True} if WAGTAIL_VERSION >= (4, 0) else {} +SF_KWARGS = {"use_json_field": True} class TestPage(Page): @@ -345,9 +343,7 @@ class TestPage(Page): FieldPanel("test_slugfield"), FieldPanel("test_urlfield"), FieldPanel("test_richtextfield"), - FieldPanel("test_streamfield") - if WAGTAIL_VERSION >= (3, 0) - else StreamFieldPanel("test_streamfield"), + FieldPanel("test_streamfield"), FieldPanel("test_snippet"), InlinePanel("test_childobjects"), FieldPanel("test_customfield"), @@ -357,9 +353,7 @@ class TestPage(Page): FieldPanel("test_synchronized_slugfield"), FieldPanel("test_synchronized_urlfield"), FieldPanel("test_synchronized_richtextfield"), - FieldPanel("test_synchronized_streamfield") - if WAGTAIL_VERSION >= (3, 0) - else StreamFieldPanel("test_synchronized_streamfield"), + FieldPanel("test_synchronized_streamfield"), FieldPanel("test_synchronized_image"), FieldPanel("test_synchronized_document"), FieldPanel("test_synchronized_snippet"), diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index 4c98cfb6..50eca991 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -1,6 +1,5 @@ import json import tempfile -import unittest import uuid import polib @@ -22,7 +21,6 @@ ) from rest_framework.settings import api_settings from rest_framework.test import APITestCase -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin.edit_handlers import FieldPanel from wagtail.core.blocks import StreamValue from wagtail.core.models import Locale, Page @@ -588,21 +586,15 @@ def test_page_chooser_in_orderable(self): orderable_page_path = ( f"test_snippet_orderable.{orderable_block_id}.orderable_page" ) - if WAGTAIL_VERSION >= (3, 0): - self.assertEqual( - segments_by_content_path[orderable_page_path]["location"]["widget"], - { - "type": "page_chooser", - "allowed_page_types": [ - "wagtailcore.page", - ], - }, - ) - else: - self.assertEqual( - segments_by_content_path[orderable_page_path]["location"]["widget"], - {"type": "unknown"}, - ) + self.assertEqual( + segments_by_content_path[orderable_page_path]["location"]["widget"], + { + "type": "page_chooser", + "allowed_page_types": [ + "wagtailcore.page", + ], + }, + ) self.assertEqual( segments_by_content_path[orderable_page_path]["location"]["subField"], "Orderable page", @@ -836,10 +828,6 @@ def test_choosers_in_stream_blocks(self): {"type": "page_chooser", "allowed_page_types": ["wagtailcore.page"]}, ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_choosers_in_listblock_in_stream_blocks(self): home_page_with_specific_type = self.home_page.add_child( instance=TestHomePage(title="Test home page", slug="test-home-page") @@ -906,10 +894,6 @@ def test_choosers_in_listblock_in_stream_blocks(self): {"type": "page_chooser", "allowed_page_types": ["wagtailcore.page"]}, ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_choosers_in_structblock_in_listblock(self): home_page_with_specific_type = self.home_page.add_child( instance=TestHomePage(title="Test home page", slug="test-home-page") @@ -1012,10 +996,6 @@ def test_choosers_in_structblock_in_listblock(self): {"type": "page_chooser", "allowed_page_types": ["wagtailcore.page"]}, ) - @unittest.skipUnless( - WAGTAIL_VERSION >= (2, 16), - "ListBlocks are supported starting with Wagtail 2.16", - ) def test_choosers_in_listblock(self): home_page_with_specific_type = self.home_page.add_child( instance=TestHomePage(title="Test home page", slug="test-home-page") diff --git a/wagtail_localize/tests/utils.py b/wagtail_localize/tests/utils.py index d45fb6f0..fb6fc211 100644 --- a/wagtail_localize/tests/utils.py +++ b/wagtail_localize/tests/utils.py @@ -1,6 +1,5 @@ from django.contrib import messages from django.urls import reverse -from wagtail import VERSION as WAGTAIL_VERSION from wagtail_localize.test.models import TestPage @@ -26,14 +25,8 @@ def make_test_page(parent, cls=None, **kwargs): def get_snippet_list_url_from_args(app_label, model_name): - if WAGTAIL_VERSION >= (4, 0): - return reverse(f"wagtailsnippets_{app_label}_{model_name}:list") - - return reverse("wagtailsnippets:list", args=[app_label, model_name]) + return reverse(f"wagtailsnippets_{app_label}_{model_name}:list") def get_snippet_add_url_from_args(app_label, model_name): - if WAGTAIL_VERSION >= (4, 0): - return reverse(f"wagtailsnippets_{app_label}_{model_name}:add") - - return reverse("wagtailsnippets:add", args=[app_label, model_name]) + return reverse(f"wagtailsnippets_{app_label}_{model_name}:add") diff --git a/wagtail_localize/views/convert.py b/wagtail_localize/views/convert.py index 63969a31..004b7a51 100644 --- a/wagtail_localize/views/convert.py +++ b/wagtail_localize/views/convert.py @@ -6,7 +6,6 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.translation import gettext as _ -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import messages from wagtail.admin.views.pages.utils import get_valid_next_url_from_request from wagtail.core.models import ( @@ -115,11 +114,8 @@ def sync_alias(source_page, alias_page, revision=None, _content_json=None): # Only compute this if necessary since it's quite a heavy operation if _content_json is None: - _content_json = source_page.to_json() - - if WAGTAIL_VERSION >= (3, 0): # see https://github.com/wagtail/wagtail/pull/8024 - _content_json = json.loads(_content_json) + _content_json = json.loads(source_page.to_json()) # FIXME: update when core adds better mechanism for the exclusions exclude_fields = [ @@ -185,7 +181,4 @@ def process_child_object(child_object): ) # Update any aliases of that alias - if WAGTAIL_VERSION >= (3, 0): - alias_page.update_aliases(revision=revision, _content=_content_json) - else: - alias_page.update_aliases(revision=revision, _content_json=_content_json) + alias_page.update_aliases(revision=revision, _content=_content_json) diff --git a/wagtail_localize/views/edit_translation.py b/wagtail_localize/views/edit_translation.py index f5123bef..6ec4c610 100644 --- a/wagtail_localize/views/edit_translation.py +++ b/wagtail_localize/views/edit_translation.py @@ -29,9 +29,12 @@ ) from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import messages from wagtail.admin.navigation import get_explorable_root_page +from wagtail.admin.panels import FieldPanel, InlinePanel, ObjectList +from wagtail.admin.panels import PanelGroup as BaseCompositeEditHandler +from wagtail.admin.panels import TabbedInterface +from wagtail.admin.panels import get_edit_handler as get_snippet_edit_handler from wagtail.admin.templatetags.wagtailadmin_tags import avatar_url from wagtail.admin.views.pages.utils import get_valid_next_url_from_request from wagtail.core import blocks @@ -45,6 +48,7 @@ from wagtail.snippets.blocks import SnippetChooserBlock from wagtail.snippets.models import get_snippet_models from wagtail.snippets.permissions import get_permission_name, user_can_edit_snippet_type +from wagtail.utils.decorators import xframe_options_sameorigin_override from wagtail_localize.compat import ( DATE_FORMAT, @@ -61,39 +65,7 @@ TranslationSource, ) from wagtail_localize.segments import StringSegmentValue - - -if WAGTAIL_VERSION >= (4, 0): - from wagtail.admin.panels import get_edit_handler as get_snippet_edit_handler - from wagtail.utils.decorators import xframe_options_sameorigin_override - - from wagtail_localize.side_panels import LocalizedPageSidePanels -else: - from wagtail.snippets.views.snippets import get_snippet_edit_handler - - def xframe_options_sameorigin_override(func): - return func - - -if WAGTAIL_VERSION >= (3, 0): - # TODO: tidy this up once we drop support for Wagtail < 3.0 - from wagtail.admin.panels import ( - FieldPanel, - InlinePanel, - ObjectList, - PageChooserPanel, - ) - from wagtail.admin.panels import PanelGroup as BaseCompositeEditHandler - from wagtail.admin.panels import TabbedInterface -else: - from wagtail.admin.edit_handlers import ( - BaseCompositeEditHandler, - FieldPanel, - InlinePanel, - ObjectList, - PageChooserPanel, - TabbedInterface, - ) +from wagtail_localize.side_panels import LocalizedPageSidePanels class UserSerializer(serializers.ModelSerializer): @@ -206,24 +178,17 @@ def tabs_with_slugs(self): @cached_property def field_tab_mapping(self): - if WAGTAIL_VERSION >= (3, 0): - # ObjectList used to inherit from TabbedInterface pre 3.0. Now they both inherit from PanelGroup - # Ideally we would check on PanelGroup, however FieldRowPanel and MultiRowPanel do so too, but we're - # only interested in "tabbing" - is_tabbed = isinstance(self.edit_handler, (TabbedInterface, ObjectList)) - else: - is_tabbed = isinstance(self.edit_handler, TabbedInterface) + # ObjectList used to inherit from TabbedInterface pre 3.0. Now they both inherit from PanelGroup + # Ideally we would check on PanelGroup, however FieldRowPanel and MultiRowPanel do so too, but we're + # only interested in "tabbing" + is_tabbed = isinstance(self.edit_handler, (TabbedInterface, ObjectList)) if is_tabbed: field_tabs = {} for tab in self.edit_handler.children: - if WAGTAIL_VERSION >= (3, 0): - form_options = tab.get_form_options() - required_fields = form_options.get("fields", []) - required_formsets = form_options.get("formsets", {}).keys() - else: - required_fields = tab.required_fields() - required_formsets = tab.required_formsets().keys() + form_options = tab.get_form_options() + required_fields = form_options.get("fields", []) + required_formsets = form_options.get("formsets", {}).keys() for tab_field in required_fields: field_tabs[tab_field] = tab.heading @@ -243,25 +208,18 @@ def get_field_tab(self, field_name): @cached_property def field_ordering_mapping(self): - if WAGTAIL_VERSION >= (3, 0): - # ObjectList used to inherit from TabbedInterface pre 3.0. Now they both inherit from PanelGroup - # Ideally we would check on PanelGroup, however FieldRowPanel and MultiRowPanel do so too, but we're - # only interested in "tabbing" - is_tabbed = isinstance(self.edit_handler, (TabbedInterface, ObjectList)) - else: - is_tabbed = isinstance(self.edit_handler, TabbedInterface) + # ObjectList used to inherit from TabbedInterface pre 3.0. Now they both inherit from PanelGroup + # Ideally we would check on PanelGroup, however FieldRowPanel and MultiRowPanel do so too, but we're + # only interested in "tabbing" + is_tabbed = isinstance(self.edit_handler, (TabbedInterface, ObjectList)) if is_tabbed: field_orderings = {} order = 0 for tab in self.edit_handler.children: - if WAGTAIL_VERSION >= (3, 0): - form_options = tab.get_form_options() - required_fields = form_options.get("fields", []) - required_formsets = form_options.get("formsets", {}) - else: - required_fields = tab.required_fields() - required_formsets = tab.required_formsets().keys() + form_options = tab.get_form_options() + required_fields = form_options.get("fields", []) + required_formsets = form_options.get("formsets", {}) for tab_field in required_fields: # TODO(someday): Orderings of fields within inline panels. # (currently, they will all be assigned the same order value, @@ -299,9 +257,7 @@ def walk(edit_handler): field_edit_handlers[edit_handler.field_name] = edit_handler elif ( - WAGTAIL_VERSION >= (3, 0) - and isinstance(edit_handler, InlinePanel) - and edit_handler.model is not None + isinstance(edit_handler, InlinePanel) and edit_handler.model is not None ): # we can only reliably get panel definitions with the relevant instance data in Wagtail 3.0+ for panel in edit_handler.panel_definitions: @@ -340,51 +296,36 @@ def widget_from_field(field): if issubclass(field.related_model, Page): edit_handler = tab_helper.get_field_edit_handler(field.name) - if WAGTAIL_VERSION >= (3, 0): - # @see https://github.com/wagtail/wagtail/pull/7684 - # the target_models is set in the ModelFieldRegistry for ForeignKeys - widget_overrides = edit_handler.get_form_options().get( - "widgets", {} - ) - # Check for explicit `page_types` kwarg in PageChooserPanel - if field.name in widget_overrides and hasattr( - widget_overrides[field.name], "target_models" - ): - allowed_page_types = [ - "{app}.{model}".format( - app=model._meta.app_label, - model=model._meta.model_name, - ) - for model in widget_overrides[field.name].target_models - ] - else: - from wagtail.admin.forms.models import registry - - allowed_page_types = [ - "{app}.{model}".format( - app=model._meta.app_label, - model=model._meta.model_name, - ) - for model in registry.foreign_key_lookup(field)[ - "widget" - ].target_models - ] - return { - "type": "page_chooser", - "allowed_page_types": allowed_page_types, - } - elif isinstance(edit_handler, PageChooserPanel): - return { - "type": "page_chooser", - "allowed_page_types": [ - "{app}.{model}".format( - app=model._meta.app_label, model=model._meta.model_name - ) - for model in edit_handler.target_models() - ], - } + # @see https://github.com/wagtail/wagtail/pull/7684 + # the target_models is set in the ModelFieldRegistry for ForeignKeys + widget_overrides = edit_handler.get_form_options().get("widgets", {}) + # Check for explicit `page_types` kwarg in PageChooserPanel + if field.name in widget_overrides and hasattr( + widget_overrides[field.name], "target_models" + ): + allowed_page_types = [ + "{app}.{model}".format( + app=model._meta.app_label, + model=model._meta.model_name, + ) + for model in widget_overrides[field.name].target_models + ] else: - return {"type": "unknown"} + from wagtail.admin.forms.models import registry + + allowed_page_types = [ + "{app}.{model}".format( + app=model._meta.app_label, + model=model._meta.model_name, + ) + for model in registry.foreign_key_lookup(field)[ + "widget" + ].target_models + ] + return { + "type": "page_chooser", + "allowed_page_types": allowed_page_types, + } elif issubclass(field.related_model, AbstractDocument): return {"type": "document_chooser"} @@ -393,23 +334,13 @@ def widget_from_field(field): return {"type": "image_chooser"} elif issubclass(field.related_model, tuple(get_snippet_models())): - if WAGTAIL_VERSION >= (4, 0, 0): - chooser_url = reverse( - "wagtailsnippetchoosers_%s_%s:choose" - % ( - field.related_model._meta.app_label, - field.related_model._meta.model_name, - ) - ) - else: - chooser_url = reverse( - "wagtailsnippets:choose", - args=[ - field.related_model._meta.app_label, - field.related_model._meta.model_name, - ], + chooser_url = reverse( + "wagtailsnippetchoosers_%s_%s:choose" + % ( + field.related_model._meta.app_label, + field.related_model._meta.model_name, ) - + ) return { "type": "snippet_chooser", "snippet_model": { @@ -451,22 +382,13 @@ def widget_from_block(block, content_components=None): return {"type": "image_chooser"} elif isinstance(block, SnippetChooserBlock): - if WAGTAIL_VERSION >= (4, 0, 0): - chooser_url = reverse( - "wagtailsnippetchoosers_%s_%s:choose" - % ( - block.target_model._meta.app_label, - block.target_model._meta.model_name, - ) - ) - else: - chooser_url = reverse( - "wagtailsnippets:choose", - args=[ - block.target_model._meta.app_label, - block.target_model._meta.model_name, - ], + chooser_url = reverse( + "wagtailsnippetchoosers_%s_%s:choose" + % ( + block.target_model._meta.app_label, + block.target_model._meta.model_name, ) + ) return { "type": "snippet_chooser", "snippet_model": { @@ -971,14 +893,10 @@ def get_translation_progress(segment, locale): else: add_convert_to_alias_url = False - if WAGTAIL_VERSION >= (4, 0): - has_legacy_styling = False - side_panels = ( - LocalizedPageSidePanels(request, instance, translation) if is_page else None - ) - else: - has_legacy_styling = True - side_panels = None + has_legacy_styling = False + side_panels = ( + LocalizedPageSidePanels(request, instance, translation) if is_page else None + ) return render( request, diff --git a/wagtail_localize/wagtail_hooks.py b/wagtail_localize/wagtail_hooks.py index e3b62498..520267c2 100644 --- a/wagtail_localize/wagtail_hooks.py +++ b/wagtail_localize/wagtail_hooks.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy from django.views.i18n import JavaScriptCatalog -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import widgets as wagtailadmin_widgets from wagtail.admin.action_menu import ActionMenuItem as PageActionMenuItem from wagtail.admin.menu import MenuItem @@ -134,16 +133,9 @@ def register_submit_translation_permission(): ) -if WAGTAIL_VERSION >= (4, 0, 0): - - def set_button_icon(button, icon_name): - button.icon_name = icon_name - return button - -else: - - def set_button_icon(button, icon_name): - return button +def set_button_icon(button, icon_name): + button.icon_name = icon_name + return button def page_listing_more_buttons(page, page_perms, next_url=None): @@ -180,22 +172,8 @@ def page_listing_more_buttons(page, page_perms, next_url=None): ) -if WAGTAIL_VERSION >= (4, 0, 0): - - hooks.register("register_page_header_buttons", page_listing_more_buttons) - hooks.register("register_page_listing_more_buttons", page_listing_more_buttons) - -else: - - if WAGTAIL_VERSION >= (2, 16, 0): - hooks.register("register_page_header_buttons", page_listing_more_buttons) - - @hooks.register("register_page_listing_more_buttons") - def register_page_listing_more_buttons( - page, page_perms, is_parent=False, next_url=None - ): - for button in page_listing_more_buttons(page, page_perms, next_url): - yield button +hooks.register("register_page_header_buttons", page_listing_more_buttons) +hooks.register("register_page_listing_more_buttons", page_listing_more_buttons) @hooks.register("register_snippet_listing_buttons") From 8bd6917303b3c1c0b5bcb2390f43f54da29d557f Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Mon, 6 Feb 2023 23:41:33 +0800 Subject: [PATCH 07/13] Removed Wagtail upperbound --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index af35b317..e737e474 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ dynamic = ["version"] requires-python = ">=3.7" dependencies = [ "Django>=3.2,<4.2", - "Wagtail>=4.1,<5.0", + "Wagtail>=4.1", "polib>=1.1,<2.0", "typing_extensions>=4.0" ] From 146b4e15bfc50974dddabe424765c3ae85028768 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Tue, 7 Feb 2023 00:33:49 +0800 Subject: [PATCH 08/13] Run updatemodulepaths --- docs/how-to/field-configuration.md | 6 +- docs/tutorial/4-templates.md | 2 +- wagtail_localize/locales/forms.py | 4 +- wagtail_localize/locales/tests.py | 4 +- wagtail_localize/locales/utils.py | 2 +- wagtail_localize/locales/views.py | 9 +- wagtail_localize/locales/wagtail_hooks.py | 4 +- .../tests/test_dummy_translator.py | 2 +- wagtail_localize/modeladmin/helpers.py | 2 +- wagtail_localize/modeladmin/options.py | 2 +- wagtail_localize/modeladmin/tests.py | 4 +- wagtail_localize/modeladmin/views.py | 2 +- wagtail_localize/modeladmin/wagtail_hooks.py | 2 +- wagtail_localize/models.py | 8 +- wagtail_localize/operations.py | 2 +- wagtail_localize/segments/extract.py | 6 +- wagtail_localize/segments/ingest.py | 6 +- .../segments/tests/test_segment_extraction.py | 4 +- .../segments/tests/test_segment_ingestion.py | 4 +- wagtail_localize/synctree.py | 4 +- .../test/migrations/0001_initial.py | 302 ++++++++------- .../0002_header_navigationlink_and_more.py | 348 +++++++++--------- wagtail_localize/test/models.py | 8 +- wagtail_localize/test/settings.py | 2 +- wagtail_localize/test/urls.py | 2 +- .../tests/test_convert_to_alias.py | 4 +- .../tests/test_edit_translation.py | 8 +- .../tests/test_submit_translations.py | 4 +- wagtail_localize/tests/test_synctree.py | 4 +- .../tests/test_translation_components.py | 4 +- .../tests/test_translation_model.py | 2 +- .../tests/test_translations_report.py | 4 +- .../tests/test_translationsource_model.py | 4 +- .../tests/test_update_translations.py | 4 +- wagtail_localize/views/convert.py | 9 +- wagtail_localize/views/edit_translation.py | 8 +- wagtail_localize/views/report.py | 2 +- wagtail_localize/views/submit_translations.py | 2 +- wagtail_localize/views/update_translations.py | 2 +- wagtail_localize/wagtail_hooks.py | 6 +- 40 files changed, 391 insertions(+), 417 deletions(-) diff --git a/docs/how-to/field-configuration.md b/docs/how-to/field-configuration.md index a7e62079..7ae543c0 100644 --- a/docs/how-to/field-configuration.md +++ b/docs/how-to/field-configuration.md @@ -50,7 +50,7 @@ For example, by default the `slug` field on pages is translatable. If you would set it up as syncronised instead using the following snippet: ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_localize.fields import SynchronizedField @@ -71,7 +71,7 @@ You can tell Wagtail to not allow the field to be overridden by passing the keyw For example: ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_localize.fields import SynchronizedField @@ -90,7 +90,7 @@ class BlogPage(Page): To completely disable Wagtail's auto generation, you can set the `translatable_fields` attribute on the model. ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_localize.fields import TranslatableField, SynchronizedField diff --git a/docs/tutorial/4-templates.md b/docs/tutorial/4-templates.md index b7694fd6..563c2467 100644 --- a/docs/tutorial/4-templates.md +++ b/docs/tutorial/4-templates.md @@ -87,7 +87,7 @@ the currently active language which can be found with `Locale.get_active()`. To implement this, open up `search/views.py` in your favourite editor, then modify the following lines: -- Change the import line `from wagtail.core.models import Page` to `from wagtail.core.models import Page, Locale` +- Change the import line `from wagtail.models import Page` to `from wagtail.models import Page, Locale` - Change the query `Page.objects.live().search(search_query)` to `Page.objects.live().filter(locale=Locale.get_active()).search(search_query)` Refresh the search page in the browser, the results should now be filtered. diff --git a/wagtail_localize/locales/forms.py b/wagtail_localize/locales/forms.py index 1d19b40c..7ec76487 100644 --- a/wagtail_localize/locales/forms.py +++ b/wagtail_localize/locales/forms.py @@ -1,7 +1,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ -from wagtail.core.models import Locale -from wagtail.core.utils import get_content_languages +from wagtail.coreutils import get_content_languages +from wagtail.models import Locale class LocaleForm(forms.ModelForm): diff --git a/wagtail_localize/locales/tests.py b/wagtail_localize/locales/tests.py index 7552adf0..75893799 100644 --- a/wagtail_localize/locales/tests.py +++ b/wagtail_localize/locales/tests.py @@ -1,8 +1,8 @@ from django.contrib.messages import get_messages from django.test import TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.locales.components import LOCALE_COMPONENTS from wagtail_localize.models import LocaleSynchronization diff --git a/wagtail_localize/locales/utils.py b/wagtail_localize/locales/utils.py index 6e66758d..8887d469 100644 --- a/wagtail_localize/locales/utils.py +++ b/wagtail_localize/locales/utils.py @@ -1,4 +1,4 @@ -from wagtail.core.models import Page, get_translatable_models +from wagtail.models import Page, get_translatable_models def get_locale_usage(locale): diff --git a/wagtail_localize/locales/views.py b/wagtail_localize/locales/views.py index 086a0bac..c0277e82 100644 --- a/wagtail_localize/locales/views.py +++ b/wagtail_localize/locales/views.py @@ -5,14 +5,11 @@ from django.utils.translation import gettext_lazy from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import messages -from wagtail.admin.edit_handlers import ( - ObjectList, - extract_panel_definitions_from_model_class, -) +from wagtail.admin.panels import ObjectList, extract_panel_definitions_from_model_class from wagtail.admin.views import generic from wagtail.admin.viewsets.model import ModelViewSet -from wagtail.core.models import Locale -from wagtail.core.permissions import locale_permission_policy +from wagtail.models import Locale +from wagtail.permissions import locale_permission_policy from wagtail_localize.components import BaseComponentManager diff --git a/wagtail_localize/locales/wagtail_hooks.py b/wagtail_localize/locales/wagtail_hooks.py index 9dd76ee5..7dfc5cdf 100644 --- a/wagtail_localize/locales/wagtail_hooks.py +++ b/wagtail_localize/locales/wagtail_hooks.py @@ -1,9 +1,9 @@ from django.contrib.auth.models import Permission from django.urls import reverse from django.utils.translation import gettext_lazy as _ +from wagtail import hooks from wagtail.admin.menu import MenuItem -from wagtail.core import hooks -from wagtail.core.permissions import site_permission_policy +from wagtail.permissions import site_permission_policy from .views import LocaleViewSet diff --git a/wagtail_localize/machine_translators/tests/test_dummy_translator.py b/wagtail_localize/machine_translators/tests/test_dummy_translator.py index 6c98d054..f27be7e6 100644 --- a/wagtail_localize/machine_translators/tests/test_dummy_translator.py +++ b/wagtail_localize/machine_translators/tests/test_dummy_translator.py @@ -1,5 +1,5 @@ from django.test import TestCase -from wagtail.core.models import Locale +from wagtail.models import Locale from wagtail_localize.machine_translators.dummy import DummyTranslator from wagtail_localize.strings import StringValue diff --git a/wagtail_localize/modeladmin/helpers.py b/wagtail_localize/modeladmin/helpers.py index ad3665ee..da23f81c 100644 --- a/wagtail_localize/modeladmin/helpers.py +++ b/wagtail_localize/modeladmin/helpers.py @@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _ from wagtail.contrib.modeladmin.helpers import ButtonHelper, PageButtonHelper from wagtail.contrib.modeladmin.views import InspectView -from wagtail.core.models import Locale, Page, TranslatableMixin +from wagtail.models import Locale, Page, TranslatableMixin from wagtail_localize.models import TranslationSource diff --git a/wagtail_localize/modeladmin/options.py b/wagtail_localize/modeladmin/options.py index 63fdf540..6a937787 100644 --- a/wagtail_localize/modeladmin/options.py +++ b/wagtail_localize/modeladmin/options.py @@ -1,7 +1,7 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from wagtail.contrib.modeladmin.options import ModelAdmin -from wagtail.core.models import TranslatableMixin +from wagtail.models import TranslatableMixin from .helpers import TranslatableButtonHelper, TranslatablePageButtonHelper from .views import ( diff --git a/wagtail_localize/modeladmin/tests.py b/wagtail_localize/modeladmin/tests.py index ce17e617..9f7db9dc 100644 --- a/wagtail_localize/modeladmin/tests.py +++ b/wagtail_localize/modeladmin/tests.py @@ -7,8 +7,8 @@ from django.core.exceptions import ImproperlyConfigured from django.test import RequestFactory, TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale, Page -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.modeladmin import helpers from wagtail_localize.modeladmin.options import ModelAdmin, TranslatableModelAdmin diff --git a/wagtail_localize/modeladmin/views.py b/wagtail_localize/modeladmin/views.py index 989da091..2965bd91 100644 --- a/wagtail_localize/modeladmin/views.py +++ b/wagtail_localize/modeladmin/views.py @@ -17,7 +17,7 @@ IndexView, InspectView, ) -from wagtail.core.models import Locale, TranslatableMixin +from wagtail.models import Locale, TranslatableMixin from wagtail.utils.version import get_main_version from wagtail_localize.models import Translation diff --git a/wagtail_localize/modeladmin/wagtail_hooks.py b/wagtail_localize/modeladmin/wagtail_hooks.py index cc1bbe05..06bec2cb 100644 --- a/wagtail_localize/modeladmin/wagtail_hooks.py +++ b/wagtail_localize/modeladmin/wagtail_hooks.py @@ -1,5 +1,5 @@ from django.urls import include, path -from wagtail.core import hooks +from wagtail import hooks from .views import SubmitModelAdminTranslationView diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index 833dd278..f4296fb9 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -36,17 +36,17 @@ get_serializable_data_for_fields, model_from_serializable_data, ) +from wagtail import blocks from wagtail.blocks.list_block import ListValue -from wagtail.core import blocks -from wagtail.core.fields import StreamField -from wagtail.core.models import ( +from wagtail.coreutils import find_available_slug +from wagtail.fields import StreamField +from wagtail.models import ( Page, PageLogEntry, TranslatableMixin, _copy, get_translatable_models, ) -from wagtail.core.utils import find_available_slug from wagtail.snippets.models import get_snippet_models from .compat import DATE_FORMAT, get_revision_model, get_snippet_edit_url diff --git a/wagtail_localize/operations.py b/wagtail_localize/operations.py index 90910d2e..6835f918 100644 --- a/wagtail_localize/operations.py +++ b/wagtail_localize/operations.py @@ -3,7 +3,7 @@ from django.conf import settings from django.core.exceptions import ValidationError from django.db import transaction -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_localize.models import Translation, TranslationSource diff --git a/wagtail_localize/segments/extract.py b/wagtail_localize/segments/extract.py index 0999b8e1..c7bf532d 100644 --- a/wagtail_localize/segments/extract.py +++ b/wagtail_localize/segments/extract.py @@ -2,9 +2,9 @@ from django.core.exceptions import ImproperlyConfigured from django.db import models from modelcluster.fields import ParentalKey -from wagtail.core import blocks -from wagtail.core.fields import RichTextField, StreamField -from wagtail.core.models import Page, TranslatableMixin +from wagtail import blocks +from wagtail.fields import RichTextField, StreamField +from wagtail.models import Page, TranslatableMixin from wagtail_localize.segments import ( OverridableSegmentValue, diff --git a/wagtail_localize/segments/ingest.py b/wagtail_localize/segments/ingest.py index 6bb22ab0..5139c963 100644 --- a/wagtail_localize/segments/ingest.py +++ b/wagtail_localize/segments/ingest.py @@ -2,9 +2,9 @@ from django.apps import apps from django.db import models -from wagtail.core import blocks -from wagtail.core.fields import RichTextField, StreamField -from wagtail.core.rich_text import RichText +from wagtail import blocks +from wagtail.fields import RichTextField, StreamField +from wagtail.rich_text import RichText from wagtail_localize.strings import restore_strings diff --git a/wagtail_localize/segments/tests/test_segment_extraction.py b/wagtail_localize/segments/tests/test_segment_extraction.py index 11a3ef6f..c19a068b 100644 --- a/wagtail_localize/segments/tests/test_segment_extraction.py +++ b/wagtail_localize/segments/tests/test_segment_extraction.py @@ -3,8 +3,8 @@ from django.core.exceptions import ImproperlyConfigured from django.test import TestCase -from wagtail.core.blocks import StreamValue -from wagtail.core.models import Page, Site +from wagtail.blocks import StreamValue +from wagtail.models import Page, Site from wagtail_localize.segments import ( OverridableSegmentValue, diff --git a/wagtail_localize/segments/tests/test_segment_ingestion.py b/wagtail_localize/segments/tests/test_segment_ingestion.py index b416b7b6..fd16c3ea 100644 --- a/wagtail_localize/segments/tests/test_segment_ingestion.py +++ b/wagtail_localize/segments/tests/test_segment_ingestion.py @@ -2,8 +2,8 @@ import uuid from django.test import TestCase -from wagtail.core.blocks import StreamValue -from wagtail.core.models import Locale, Page +from wagtail.blocks import StreamValue +from wagtail.models import Locale, Page from wagtail_localize.fields import copy_synchronised_fields from wagtail_localize.segments import ( diff --git a/wagtail_localize/synctree.py b/wagtail_localize/synctree.py index af6abaaa..f977b144 100644 --- a/wagtail_localize/synctree.py +++ b/wagtail_localize/synctree.py @@ -1,8 +1,8 @@ from collections import defaultdict from django.utils.functional import cached_property -from wagtail.core import hooks -from wagtail.core.models import Locale, Page +from wagtail import hooks +from wagtail.models import Locale, Page class PageIndex: diff --git a/wagtail_localize/test/migrations/0001_initial.py b/wagtail_localize/test/migrations/0001_initial.py index db97db68..eff94cad 100644 --- a/wagtail_localize/test/migrations/0001_initial.py +++ b/wagtail_localize/test/migrations/0001_initial.py @@ -4,9 +4,9 @@ import django.db.models.deletion import modelcluster.fields import uuid -import wagtail.core.blocks -import wagtail.core.blocks.field_block -import wagtail.core.fields +import wagtail.blocks +import wagtail.blocks.field_block +import wagtail.fields import wagtail.documents.blocks import wagtail.embeds.blocks import wagtail.images.blocks @@ -120,66 +120,62 @@ class Migration(migrations.Migration): ("test_emailfield", models.EmailField(blank=True, max_length=254)), ("test_slugfield", models.SlugField(blank=True)), ("test_urlfield", models.URLField(blank=True)), - ("test_richtextfield", wagtail.core.fields.RichTextField(blank=True)), + ("test_richtextfield", wagtail.fields.RichTextField(blank=True)), ( "test_streamfield", - wagtail.core.fields.StreamField( + wagtail.fields.StreamField( [ ( "test_charblock", - wagtail.core.blocks.CharBlock(max_length=255), + wagtail.blocks.CharBlock(max_length=255), ), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), ( "test_blockquoteblock", - wagtail.core.blocks.BlockQuoteBlock(), + wagtail.blocks.BlockQuoteBlock(), ), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.TextBlock() - ), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock( - required=False - ), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -187,8 +183,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -200,35 +196,35 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), ( "chooser", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -236,23 +232,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -265,10 +261,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -278,11 +274,11 @@ class Migration(migrations.Migration): ), ( "test_pagechooserblock", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -312,21 +308,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -441,70 +437,66 @@ class Migration(migrations.Migration): ("test_emailfield", models.EmailField(blank=True, max_length=254)), ("test_slugfield", models.SlugField(blank=True)), ("test_urlfield", models.URLField(blank=True)), - ("test_richtextfield", wagtail.core.fields.RichTextField(blank=True)), + ("test_richtextfield", wagtail.fields.RichTextField(blank=True)), ( "test_null_richtextfield", - wagtail.core.fields.RichTextField(blank=True, null=True), + wagtail.fields.RichTextField(blank=True, null=True), ), ( "test_streamfield", - wagtail.core.fields.StreamField( + wagtail.fields.StreamField( [ ( "test_charblock", - wagtail.core.blocks.CharBlock(max_length=255), + wagtail.blocks.CharBlock(max_length=255), ), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), ( "test_blockquoteblock", - wagtail.core.blocks.BlockQuoteBlock(), + wagtail.blocks.BlockQuoteBlock(), ), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.TextBlock() - ), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock( - required=False - ), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -512,8 +504,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -525,35 +517,35 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), ( "chooser", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -561,23 +553,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -590,10 +582,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -603,11 +595,11 @@ class Migration(migrations.Migration): ), ( "test_pagechooserblock", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -637,21 +629,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -684,67 +676,63 @@ class Migration(migrations.Migration): ("test_synchronized_urlfield", models.URLField(blank=True)), ( "test_synchronized_richtextfield", - wagtail.core.fields.RichTextField(blank=True), + wagtail.fields.RichTextField(blank=True), ), ( "test_synchronized_streamfield", - wagtail.core.fields.StreamField( + wagtail.fields.StreamField( [ ( "test_charblock", - wagtail.core.blocks.CharBlock(max_length=255), + wagtail.blocks.CharBlock(max_length=255), ), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), ( "test_blockquoteblock", - wagtail.core.blocks.BlockQuoteBlock(), + wagtail.blocks.BlockQuoteBlock(), ), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.TextBlock() - ), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock( - required=False - ), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -752,8 +740,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -765,35 +753,35 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), ( "chooser", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -801,23 +789,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -830,10 +818,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -843,11 +831,11 @@ class Migration(migrations.Migration): ), ( "test_pagechooserblock", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -877,21 +865,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), diff --git a/wagtail_localize/test/migrations/0002_header_navigationlink_and_more.py b/wagtail_localize/test/migrations/0002_header_navigationlink_and_more.py index 30537fae..1879eb70 100644 --- a/wagtail_localize/test/migrations/0002_header_navigationlink_and_more.py +++ b/wagtail_localize/test/migrations/0002_header_navigationlink_and_more.py @@ -4,9 +4,9 @@ import django.db.models.deletion import modelcluster.fields import uuid -import wagtail.core.blocks -import wagtail.core.blocks.field_block -import wagtail.core.fields +import wagtail.blocks +import wagtail.blocks.field_block +import wagtail.fields import wagtail.documents.blocks import wagtail.embeds.blocks import wagtail.images.blocks @@ -111,53 +111,53 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="testgeneratetranslatablefieldspage", name="test_streamfield", - field=wagtail.core.fields.StreamField( + field=wagtail.fields.StreamField( [ - ("test_charblock", wagtail.core.blocks.CharBlock(max_length=255)), + ("test_charblock", wagtail.blocks.CharBlock(max_length=255)), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), - ("test_blockquoteblock", wagtail.core.blocks.BlockQuoteBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), + ("test_blockquoteblock", wagtail.blocks.BlockQuoteBlock()), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock(wagtail.core.blocks.TextBlock()), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -165,8 +165,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -178,32 +178,32 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), - ("chooser", wagtail.core.blocks.PageChooserBlock()), + ("chooser", wagtail.blocks.PageChooserBlock()), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -211,23 +211,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -240,10 +240,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -251,10 +251,10 @@ class Migration(migrations.Migration): "test_customblockwithoutextractmethod", wagtail_localize.test.models.CustomBlockWithoutExtractMethod(), ), - ("test_pagechooserblock", wagtail.core.blocks.PageChooserBlock()), + ("test_pagechooserblock", wagtail.blocks.PageChooserBlock()), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -284,21 +284,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -308,14 +308,12 @@ class Migration(migrations.Migration): ), ( "test_chooser_in_struct_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( - required=False - ), + wagtail.blocks.PageChooserBlock(required=False), ) ] ) @@ -323,29 +321,29 @@ class Migration(migrations.Migration): ), ( "test_image_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.images.blocks.ImageChooserBlock() ), ), ( "test_document_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.documents.blocks.DocumentChooserBlock() ), ), ( "test_chooser_in_struct_in_list_in_stream_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StreamBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StreamBlock( [ ( "list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( required=False ), ) @@ -364,53 +362,53 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="testpage", name="test_streamfield", - field=wagtail.core.fields.StreamField( + field=wagtail.fields.StreamField( [ - ("test_charblock", wagtail.core.blocks.CharBlock(max_length=255)), + ("test_charblock", wagtail.blocks.CharBlock(max_length=255)), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), - ("test_blockquoteblock", wagtail.core.blocks.BlockQuoteBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), + ("test_blockquoteblock", wagtail.blocks.BlockQuoteBlock()), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock(wagtail.core.blocks.TextBlock()), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -418,8 +416,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -431,32 +429,32 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), - ("chooser", wagtail.core.blocks.PageChooserBlock()), + ("chooser", wagtail.blocks.PageChooserBlock()), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -464,23 +462,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -493,10 +491,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -504,10 +502,10 @@ class Migration(migrations.Migration): "test_customblockwithoutextractmethod", wagtail_localize.test.models.CustomBlockWithoutExtractMethod(), ), - ("test_pagechooserblock", wagtail.core.blocks.PageChooserBlock()), + ("test_pagechooserblock", wagtail.blocks.PageChooserBlock()), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -537,21 +535,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -561,14 +559,12 @@ class Migration(migrations.Migration): ), ( "test_chooser_in_struct_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( - required=False - ), + wagtail.blocks.PageChooserBlock(required=False), ) ] ) @@ -576,29 +572,29 @@ class Migration(migrations.Migration): ), ( "test_image_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.images.blocks.ImageChooserBlock() ), ), ( "test_document_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.documents.blocks.DocumentChooserBlock() ), ), ( "test_chooser_in_struct_in_list_in_stream_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StreamBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StreamBlock( [ ( "list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( required=False ), ) @@ -617,53 +613,53 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="testpage", name="test_synchronized_streamfield", - field=wagtail.core.fields.StreamField( + field=wagtail.fields.StreamField( [ - ("test_charblock", wagtail.core.blocks.CharBlock(max_length=255)), + ("test_charblock", wagtail.blocks.CharBlock(max_length=255)), ( "test_textblock", - wagtail.core.blocks.TextBlock(label="text block"), + wagtail.blocks.TextBlock(label="text block"), ), - ("test_emailblock", wagtail.core.blocks.EmailBlock()), - ("test_urlblock", wagtail.core.blocks.URLBlock()), - ("test_richtextblock", wagtail.core.blocks.RichTextBlock()), - ("test_rawhtmlblock", wagtail.core.blocks.RawHTMLBlock()), - ("test_blockquoteblock", wagtail.core.blocks.BlockQuoteBlock()), + ("test_emailblock", wagtail.blocks.EmailBlock()), + ("test_urlblock", wagtail.blocks.URLBlock()), + ("test_richtextblock", wagtail.blocks.RichTextBlock()), + ("test_rawhtmlblock", wagtail.blocks.RawHTMLBlock()), + ("test_blockquoteblock", wagtail.blocks.BlockQuoteBlock()), ( "test_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), ( "test_listblock", - wagtail.core.blocks.ListBlock(wagtail.core.blocks.TextBlock()), + wagtail.blocks.ListBlock(wagtail.blocks.TextBlock()), ), ( "test_listblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "title", - wagtail.core.blocks.CharBlock(required=False), + wagtail.blocks.CharBlock(required=False), ), ( "items", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.field_block.CharBlock + wagtail.blocks.ListBlock( + wagtail.blocks.field_block.CharBlock ), ), ( "links_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "heading", - wagtail.core.blocks.CharBlock( + wagtail.blocks.CharBlock( blank=True, label="List Heading", required=False, @@ -671,8 +667,8 @@ class Migration(migrations.Migration): ), ( "pages", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -684,32 +680,32 @@ class Migration(migrations.Migration): ), ( "test_nestedstreamblock", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ - ("block_a", wagtail.core.blocks.TextBlock()), - ("block_b", wagtail.core.blocks.TextBlock()), + ("block_a", wagtail.blocks.TextBlock()), + ("block_b", wagtail.blocks.TextBlock()), ( "block_l", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.CharBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.CharBlock() ), ), - ("chooser", wagtail.core.blocks.PageChooserBlock()), + ("chooser", wagtail.blocks.PageChooserBlock()), ( "chooser_in_struct", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), ), ( "chooser_in_list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.PageChooserBlock() + wagtail.blocks.ListBlock( + wagtail.blocks.PageChooserBlock() ), ), ] @@ -717,23 +713,23 @@ class Migration(migrations.Migration): ), ( "test_streamblock_in_structblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_stream", - wagtail.core.blocks.StreamBlock( + wagtail.blocks.StreamBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ), ( "checklist", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -746,10 +742,10 @@ class Migration(migrations.Migration): ), ( "test_customstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ - ("field_a", wagtail.core.blocks.TextBlock()), - ("field_b", wagtail.core.blocks.TextBlock()), + ("field_a", wagtail.blocks.TextBlock()), + ("field_b", wagtail.blocks.TextBlock()), ] ), ), @@ -757,10 +753,10 @@ class Migration(migrations.Migration): "test_customblockwithoutextractmethod", wagtail_localize.test.models.CustomBlockWithoutExtractMethod(), ), - ("test_pagechooserblock", wagtail.core.blocks.PageChooserBlock()), + ("test_pagechooserblock", wagtail.blocks.PageChooserBlock()), ( "test_pagechooserblock_with_restricted_types", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( [ "wagtail_localize_test.TestHomePage", "wagtail_localize_test.TestPage", @@ -790,21 +786,21 @@ class Migration(migrations.Migration): ("test_embedblock", wagtail.embeds.blocks.EmbedBlock()), ( "test_chooserstructblock", - wagtail.core.blocks.StructBlock( - [("page", wagtail.core.blocks.PageChooserBlock())] + wagtail.blocks.StructBlock( + [("page", wagtail.blocks.PageChooserBlock())] ), ), ( "test_nestedchooserstructblock", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "nested_page", - wagtail.core.blocks.StructBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock(), + wagtail.blocks.PageChooserBlock(), ) ] ), @@ -814,14 +810,12 @@ class Migration(migrations.Migration): ), ( "test_chooser_in_struct_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( - required=False - ), + wagtail.blocks.PageChooserBlock(required=False), ) ] ) @@ -829,29 +823,29 @@ class Migration(migrations.Migration): ), ( "test_image_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.images.blocks.ImageChooserBlock() ), ), ( "test_document_chooser_in_listblock", - wagtail.core.blocks.ListBlock( + wagtail.blocks.ListBlock( wagtail.documents.blocks.DocumentChooserBlock() ), ), ( "test_chooser_in_struct_in_list_in_stream_in_listblock", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StreamBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StreamBlock( [ ( "list", - wagtail.core.blocks.ListBlock( - wagtail.core.blocks.StructBlock( + wagtail.blocks.ListBlock( + wagtail.blocks.StructBlock( [ ( "page", - wagtail.core.blocks.PageChooserBlock( + wagtail.blocks.PageChooserBlock( required=False ), ) diff --git a/wagtail_localize/test/models.py b/wagtail_localize/test/models.py index 2db5ed75..5936d912 100644 --- a/wagtail_localize/test/models.py +++ b/wagtail_localize/test/models.py @@ -4,19 +4,19 @@ from django.utils.translation import gettext_lazy from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail.admin.edit_handlers import ( +from wagtail import blocks, telepath +from wagtail.admin.panels import ( FieldPanel, InlinePanel, ObjectList, PageChooserPanel, TabbedInterface, ) -from wagtail.core import blocks, telepath -from wagtail.core.fields import RichTextField, StreamField -from wagtail.core.models import Orderable, Page, TranslatableMixin from wagtail.documents.blocks import DocumentChooserBlock from wagtail.embeds.blocks import EmbedBlock +from wagtail.fields import RichTextField, StreamField from wagtail.images.blocks import ImageChooserBlock +from wagtail.models import Orderable, Page, TranslatableMixin from wagtail.snippets.blocks import SnippetChooserBlock from wagtail.snippets.models import register_snippet diff --git a/wagtail_localize/test/settings.py b/wagtail_localize/test/settings.py index bbe55580..60c83001 100644 --- a/wagtail_localize/test/settings.py +++ b/wagtail_localize/test/settings.py @@ -52,7 +52,7 @@ "wagtail.contrib.modeladmin", "wagtail.contrib.routable_page", "wagtail.sites", - "wagtail.core", + "wagtail", "taggit", "rest_framework", "django.contrib.admin", diff --git a/wagtail_localize/test/urls.py b/wagtail_localize/test/urls.py index f089f6af..1e702edc 100644 --- a/wagtail_localize/test/urls.py +++ b/wagtail_localize/test/urls.py @@ -2,8 +2,8 @@ from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.urls import path +from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls -from wagtail.core import urls as wagtail_urls from wagtail.documents import urls as wagtaildocs_urls diff --git a/wagtail_localize/tests/test_convert_to_alias.py b/wagtail_localize/tests/test_convert_to_alias.py index 7d782e6e..275d0ea2 100644 --- a/wagtail_localize/tests/test_convert_to_alias.py +++ b/wagtail_localize/tests/test_convert_to_alias.py @@ -1,7 +1,7 @@ from django.test import TestCase from django.urls import reverse -from wagtail.core.models import Locale, Page, PageLogEntry -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page, PageLogEntry +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.models import LocaleSynchronization, Translation from wagtail_localize.test.models import TestPage diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index 50eca991..9ce9365b 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -21,13 +21,13 @@ ) from rest_framework.settings import api_settings from rest_framework.test import APITestCase -from wagtail.admin.edit_handlers import FieldPanel -from wagtail.core.blocks import StreamValue -from wagtail.core.models import Locale, Page +from wagtail.admin.panels import FieldPanel +from wagtail.blocks import StreamValue from wagtail.documents.models import Document from wagtail.images.models import Image from wagtail.images.tests.utils import get_test_image_file -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.compat import get_snippet_delete_url, get_snippet_edit_url from wagtail_localize.models import ( diff --git a/wagtail_localize/tests/test_submit_translations.py b/wagtail_localize/tests/test_submit_translations.py index 981bce88..816d8168 100644 --- a/wagtail_localize/tests/test_submit_translations.py +++ b/wagtail_localize/tests/test_submit_translations.py @@ -3,8 +3,8 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale, Page, PageViewRestriction -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page, PageViewRestriction +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.compat import get_snippet_edit_url from wagtail_localize.models import Translation, TranslationSource diff --git a/wagtail_localize/tests/test_synctree.py b/wagtail_localize/tests/test_synctree.py index 442fc733..20ba0493 100644 --- a/wagtail_localize/tests/test_synctree.py +++ b/wagtail_localize/tests/test_synctree.py @@ -1,8 +1,8 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase from django.urls import reverse -from wagtail.core.models import Locale, Page -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.models import LocaleSynchronization from wagtail_localize.synctree import PageIndex diff --git a/wagtail_localize/tests/test_translation_components.py b/wagtail_localize/tests/test_translation_components.py index 4f370d4b..02d71952 100644 --- a/wagtail_localize/tests/test_translation_components.py +++ b/wagtail_localize/tests/test_translation_components.py @@ -1,7 +1,7 @@ from django.test import TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale, Page -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.test.models import ( CustomButSimpleTranslationData, diff --git a/wagtail_localize/tests/test_translation_model.py b/wagtail_localize/tests/test_translation_model.py index 3365b8a0..74bbeabe 100644 --- a/wagtail_localize/tests/test_translation_model.py +++ b/wagtail_localize/tests/test_translation_model.py @@ -4,7 +4,7 @@ from django.test import TestCase, override_settings from django.utils import timezone -from wagtail.core.models import Locale, Page +from wagtail.models import Locale, Page from wagtail_localize.models import ( CannotSaveDraftError, diff --git a/wagtail_localize/tests/test_translations_report.py b/wagtail_localize/tests/test_translations_report.py index a3d5227d..edfd0c46 100644 --- a/wagtail_localize/tests/test_translations_report.py +++ b/wagtail_localize/tests/test_translations_report.py @@ -1,8 +1,8 @@ from django.contrib.contenttypes.models import ContentType from django.test import TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale, Page -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.models import Translation, TranslationSource from wagtail_localize.test.models import TestSnippet diff --git a/wagtail_localize/tests/test_translationsource_model.py b/wagtail_localize/tests/test_translationsource_model.py index 66add5ff..38429e77 100644 --- a/wagtail_localize/tests/test_translationsource_model.py +++ b/wagtail_localize/tests/test_translationsource_model.py @@ -4,8 +4,8 @@ from django.core.exceptions import ValidationError from django.test import TestCase, override_settings from django.utils import timezone -from wagtail.core.blocks import StreamValue -from wagtail.core.models import Locale, Page, PageLogEntry +from wagtail.blocks import StreamValue +from wagtail.models import Locale, Page, PageLogEntry from wagtail_localize.models import ( MissingRelatedObjectError, diff --git a/wagtail_localize/tests/test_update_translations.py b/wagtail_localize/tests/test_update_translations.py index 38a4e3d7..91fd013b 100644 --- a/wagtail_localize/tests/test_update_translations.py +++ b/wagtail_localize/tests/test_update_translations.py @@ -6,8 +6,8 @@ from django.core.exceptions import ValidationError from django.test import TestCase, override_settings from django.urls import reverse -from wagtail.core.models import Locale, Page, PageViewRestriction -from wagtail.tests.utils import WagtailTestUtils +from wagtail.models import Locale, Page, PageViewRestriction +from wagtail.test.utils import WagtailTestUtils from wagtail_localize.compat import get_snippet_edit_url from wagtail_localize.models import StringSegment, Translation, TranslationSource diff --git a/wagtail_localize/views/convert.py b/wagtail_localize/views/convert.py index 004b7a51..d0392400 100644 --- a/wagtail_localize/views/convert.py +++ b/wagtail_localize/views/convert.py @@ -8,13 +8,8 @@ from django.utils.translation import gettext as _ from wagtail.admin import messages from wagtail.admin.views.pages.utils import get_valid_next_url_from_request -from wagtail.core.models import ( - Page, - PageLogEntry, - TranslatableMixin, - _copy_m2m_relations, -) -from wagtail.core.signals import page_published +from wagtail.models import Page, PageLogEntry, TranslatableMixin, _copy_m2m_relations +from wagtail.signals import page_published from wagtail_localize.models import Translation, TranslationSource diff --git a/wagtail_localize/views/edit_translation.py b/wagtail_localize/views/edit_translation.py index 6ec4c610..2ef8997b 100644 --- a/wagtail_localize/views/edit_translation.py +++ b/wagtail_localize/views/edit_translation.py @@ -29,6 +29,7 @@ ) from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response +from wagtail import blocks from wagtail.admin import messages from wagtail.admin.navigation import get_explorable_root_page from wagtail.admin.panels import FieldPanel, InlinePanel, ObjectList @@ -37,14 +38,13 @@ from wagtail.admin.panels import get_edit_handler as get_snippet_edit_handler from wagtail.admin.templatetags.wagtailadmin_tags import avatar_url from wagtail.admin.views.pages.utils import get_valid_next_url_from_request -from wagtail.core import blocks -from wagtail.core.fields import StreamField -from wagtail.core.models import Page, TranslatableMixin -from wagtail.core.utils import cautious_slugify +from wagtail.coreutils import cautious_slugify from wagtail.documents.blocks import DocumentChooserBlock from wagtail.documents.models import AbstractDocument +from wagtail.fields import StreamField from wagtail.images.blocks import ImageChooserBlock from wagtail.images.models import AbstractImage +from wagtail.models import Page, TranslatableMixin from wagtail.snippets.blocks import SnippetChooserBlock from wagtail.snippets.models import get_snippet_models from wagtail.snippets.permissions import get_permission_name, user_can_edit_snippet_type diff --git a/wagtail_localize/views/report.py b/wagtail_localize/views/report.py index 6f2e5f10..2dce4594 100644 --- a/wagtail_localize/views/report.py +++ b/wagtail_localize/views/report.py @@ -8,7 +8,7 @@ from modelcluster.fields import ParentalKey from wagtail.admin.filters import WagtailFilterSet from wagtail.admin.views.reports import ReportView -from wagtail.core.models import get_translatable_models +from wagtail.models import get_translatable_models from wagtail_localize.models import Translation diff --git a/wagtail_localize/views/submit_translations.py b/wagtail_localize/views/submit_translations.py index cfec7b4e..4bb3c258 100644 --- a/wagtail_localize/views/submit_translations.py +++ b/wagtail_localize/views/submit_translations.py @@ -11,7 +11,7 @@ from django.views.generic import TemplateView from django.views.generic.detail import SingleObjectMixin from wagtail.admin.views.pages.utils import get_valid_next_url_from_request -from wagtail.core.models import Locale, Page, TranslatableMixin +from wagtail.models import Locale, Page, TranslatableMixin from wagtail.snippets.views.snippets import get_snippet_model_from_url_params from wagtail_localize.compat import get_snippet_edit_url_from_args diff --git a/wagtail_localize/views/update_translations.py b/wagtail_localize/views/update_translations.py index 7096cafa..97c3e800 100644 --- a/wagtail_localize/views/update_translations.py +++ b/wagtail_localize/views/update_translations.py @@ -11,7 +11,7 @@ from django.views.generic import TemplateView from django.views.generic.detail import SingleObjectMixin from wagtail.admin.views.pages.utils import get_valid_next_url_from_request -from wagtail.core.models import Page +from wagtail.models import Page from wagtail.snippets.models import get_snippet_models from wagtail.utils.version import get_main_version diff --git a/wagtail_localize/wagtail_hooks.py b/wagtail_localize/wagtail_hooks.py index 520267c2..0150ed06 100644 --- a/wagtail_localize/wagtail_hooks.py +++ b/wagtail_localize/wagtail_hooks.py @@ -8,12 +8,12 @@ from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy from django.views.i18n import JavaScriptCatalog +from wagtail import hooks from wagtail.admin import widgets as wagtailadmin_widgets from wagtail.admin.action_menu import ActionMenuItem as PageActionMenuItem from wagtail.admin.menu import MenuItem -from wagtail.core import hooks -from wagtail.core.log_actions import LogFormatter -from wagtail.core.models import Locale, Page, TranslatableMixin +from wagtail.log_actions import LogFormatter +from wagtail.models import Locale, Page, TranslatableMixin from wagtail.snippets.action_menu import ActionMenuItem as SnippetActionMenuItem from wagtail.snippets.widgets import SnippetListingButton From 415a156a6685ef9c2bba76e7df477fdd5bed4e99 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Tue, 7 Feb 2023 18:05:10 +0800 Subject: [PATCH 09/13] Dropped legacy code and conditionals, reverted modification on main migration, dropped compat functions --- wagtail_localize/compat.py | 31 - wagtail_localize/migrations/0001_initial.py | 62 +- wagtail_localize/models.py | 9 +- wagtail_localize/static_src/editor/main.tsx | 4 - .../common/components/ActionMenu/index.tsx | 175 ---- .../legacy/common/components/Avatar/index.tsx | 34 - .../components/DocumentChooser/index.tsx | 76 -- .../legacy/common/components/Header/index.tsx | 317 ------ .../legacy/common/components/Icon/index.tsx | 23 - .../common/components/ImageChooser/index.tsx | 88 -- .../common/components/PageChooser/index.tsx | 74 -- .../common/components/Section/index.tsx | 66 -- .../components/SnippetChooser/index.tsx | 99 -- .../legacy/common/components/Tabs/index.tsx | 147 --- .../static_src/legacy/component_form/main.css | 42 - .../static_src/legacy/component_form/main.tsx | 37 - .../static_src/legacy/custom.d.ts | 8 - .../TranslationEditor/cloud-solid.svg | 1 - .../components/TranslationEditor/footer.tsx | 158 --- .../components/TranslationEditor/header.tsx | 191 ---- .../components/TranslationEditor/index.tsx | 323 ------ .../components/TranslationEditor/reducer.ts | 209 ---- .../components/TranslationEditor/segments.tsx | 963 ------------------ .../components/TranslationEditor/toolbox.tsx | 172 ---- .../static_src/legacy/editor/main.tsx | 30 - wagtail_localize/static_src/legacy/main.tsx | 1 - .../admin/edit_translation.html | 54 +- wagtail_localize/test/models.py | 9 +- .../tests/test_edit_translation.py | 164 ++- .../tests/test_submit_translations.py | 28 +- .../tests/test_update_translations.py | 32 +- wagtail_localize/tests/utils.py | 8 - wagtail_localize/views/edit_translation.py | 26 +- wagtail_localize/views/snippets_api.py | 9 +- wagtail_localize/views/submit_translations.py | 18 +- wagtail_localize/views/update_translations.py | 11 +- wagtail_localize/wagtail_hooks.py | 20 +- 37 files changed, 269 insertions(+), 3450 deletions(-) delete mode 100644 wagtail_localize/static_src/legacy/common/components/ActionMenu/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/Avatar/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/DocumentChooser/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/Header/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/Icon/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/ImageChooser/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/PageChooser/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/Section/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/SnippetChooser/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/common/components/Tabs/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/component_form/main.css delete mode 100644 wagtail_localize/static_src/legacy/component_form/main.tsx delete mode 100644 wagtail_localize/static_src/legacy/custom.d.ts delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/cloud-solid.svg delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/header.tsx delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/index.tsx delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/reducer.ts delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/segments.tsx delete mode 100644 wagtail_localize/static_src/legacy/editor/components/TranslationEditor/toolbox.tsx delete mode 100644 wagtail_localize/static_src/legacy/editor/main.tsx delete mode 100644 wagtail_localize/static_src/legacy/main.tsx diff --git a/wagtail_localize/compat.py b/wagtail_localize/compat.py index b16bd297..4eb164d4 100644 --- a/wagtail_localize/compat.py +++ b/wagtail_localize/compat.py @@ -1,8 +1,5 @@ import os -from django.contrib.admin.utils import quote -from django.urls import reverse - if os.name == "nt": # Windows has a different strftime format for dates without leading 0 @@ -10,31 +7,3 @@ DATE_FORMAT = "%#d %B %Y" else: DATE_FORMAT = "%-d %B %Y" - - -def get_snippet_list_url(snippet): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:list" - ) - - -def get_snippet_edit_url(snippet): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:edit", - args=[quote(snippet.pk)], - ) - - -def get_snippet_edit_url_from_args(app_label, model_name, pk): - return reverse(f"wagtailsnippets_{app_label}_{model_name}:edit", args=[quote(pk)]) - - -def get_snippet_delete_url(snippet): - return reverse( - f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:delete", - args=[quote(snippet.pk)], - ) - - -def get_revision_model(): - return "wagtailcore.Revision" diff --git a/wagtail_localize/migrations/0001_initial.py b/wagtail_localize/migrations/0001_initial.py index f171d4ab..09a03a36 100644 --- a/wagtail_localize/migrations/0001_initial.py +++ b/wagtail_localize/migrations/0001_initial.py @@ -4,6 +4,7 @@ from django.db import migrations, models from django.db.migrations.recorder import MigrationRecorder +from wagtail import VERSION as WAGTAIL_VERSION def get_run_before_and_revision_model(): @@ -11,43 +12,44 @@ def get_run_before_and_revision_model(): run_before = [] revision_model = "wagtailcore.PageRevision" - # The return value of this function is used in the Migration class - # definition, so everything in this check happens at module load time - # (i.e. at the start of the `migrate` command). + if WAGTAIL_VERSION >= (4, 0, 0): + # The return value of this function is used in the Migration class + # definition, so everything in this check happens at module load time + # (i.e. at the start of the `migrate` command). - # Changing the core migration dependency potentially breaks existing - # users as it can cause an InconsistentMigrationHistory error. + # Changing the core migration dependency potentially breaks existing + # users as it can cause an InconsistentMigrationHistory error. - # Based on the dependencies, this migration can be run both before or - # after the PageRevision model is renamed to Revision. As a result, - # we cannot accurately determine the revision_model to use. + # Based on the dependencies, this migration can be run both before or + # after the PageRevision model is renamed to Revision. As a result, + # we cannot accurately determine the revision_model to use. - # What we can do instead is keep pointing to the old PageRevision name, - # but use run_before to make sure that this migration is run before the - # core migration that renames the PageRevision model. - run_before = [("wagtailcore", "0070_rename_pagerevision_revision")] + # What we can do instead is keep pointing to the old PageRevision name, + # but use run_before to make sure that this migration is run before the + # core migration that renames the PageRevision model. + run_before = [("wagtailcore", "0070_rename_pagerevision_revision")] - try: - if MigrationRecorder.Migration.objects.filter( - app="wagtailcore", name="0070_rename_pagerevision_revision" - ).exists(): - # However, if the core migration has already been applied in a - # previous `migrate` run, we should unset run_before to avoid an - # InconsistentMigrationHistory error. + try: + if MigrationRecorder.Migration.objects.filter( + app="wagtailcore", name="0070_rename_pagerevision_revision" + ).exists(): + # However, if the core migration has already been applied in a + # previous `migrate` run, we should unset run_before to avoid an + # InconsistentMigrationHistory error. - # This might be the case if the core migration was run - # separately and an earlier version of wagtail-localize were - # already installed where we did not ensure this migration was - # run before the core migration. - run_before = [] + # This might be the case if the core migration was run + # separately and an earlier version of wagtail-localize were + # already installed where we did not ensure this migration was + # run before the core migration. + run_before = [] - # In any case, it should be safe to point to the new Revision - # model name as the core migration has already been applied. - revision_model = "wagtailcore.Revision" + # In any case, it should be safe to point to the new Revision + # model name as the core migration has already been applied. + revision_model = "wagtailcore.Revision" - except (django.db.utils.OperationalError, django.db.utils.ProgrammingError): - # Normally happens when running tests. - pass + except (django.db.utils.OperationalError, django.db.utils.ProgrammingError): + # Normally happens when running tests. + pass return run_before, revision_model diff --git a/wagtail_localize/models.py b/wagtail_localize/models.py index f4296fb9..9f41f4b5 100644 --- a/wagtail_localize/models.py +++ b/wagtail_localize/models.py @@ -49,7 +49,7 @@ ) from wagtail.snippets.models import get_snippet_models -from .compat import DATE_FORMAT, get_revision_model, get_snippet_edit_url +from .compat import DATE_FORMAT from .fields import copy_synchronised_fields from .locales.components import LocaleComponentModelForm, register_locale_component from .segments import ( @@ -111,7 +111,10 @@ def get_edit_url(instance): return reverse("wagtailadmin_pages:edit", args=[instance.id]) elif instance._meta.model in get_snippet_models(): - return get_snippet_edit_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return reverse( @@ -1352,7 +1355,7 @@ class TranslationLog(models.Model): ) created_at = models.DateTimeField(auto_now_add=True) page_revision = models.ForeignKey( - get_revision_model(), + "wagtailcore.Revision", on_delete=models.SET_NULL, null=True, blank=True, diff --git a/wagtail_localize/static_src/editor/main.tsx b/wagtail_localize/static_src/editor/main.tsx index 0ca9a6f3..489a5b8d 100644 --- a/wagtail_localize/static_src/editor/main.tsx +++ b/wagtail_localize/static_src/editor/main.tsx @@ -1,7 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; import TranslationEditor from './components/TranslationEditor'; -import LegacyTranslationEditor from '../legacy/editor/components/TranslationEditor'; document.addEventListener('DOMContentLoaded', async () => { const element = document.querySelector('.js-translation-editor'); @@ -17,9 +16,6 @@ document.addEventListener('DOMContentLoaded', async () => { const props = JSON.parse(element.dataset.props); let Component = TranslationEditor; - if (props.has_legacy_styling) { - Component = LegacyTranslationEditor; - } ReactDOM.render( , diff --git a/wagtail_localize/static_src/legacy/common/components/ActionMenu/index.tsx b/wagtail_localize/static_src/legacy/common/components/ActionMenu/index.tsx deleted file mode 100644 index 9f155c80..00000000 --- a/wagtail_localize/static_src/legacy/common/components/ActionMenu/index.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -import Icon from '../Icon'; - -interface ActionMenuButtonActionProps { - label: string; - onClick: () => void; - title?: string; - classes?: string[]; - icon?: string; -} - -export const ActionMenuButtonAction: FunctionComponent< - ActionMenuButtonActionProps -> = ({ label, onClick, title, classes, icon }) => { - let classNames = ['button']; - - if (classes) { - classNames = classNames.concat(classes); - } - - return ( - - ); -}; - -interface ActionMenuLinkActionProps { - label: string; - href: string; - title?: string; - classes?: string[]; - icon?: string; -} - -export const ActionMenuLinkAction: FunctionComponent< - ActionMenuLinkActionProps -> = ({ label, href, title, classes, icon }) => { - let classNames = ['button']; - - if (classes) { - classNames = classNames.concat(classes); - } - - return ( - - {icon && } {label} - - ); -}; - -export interface PreviewMode { - mode: string; - label: string; - url: string; -} - -interface ActionMenuProps { - defaultAction: React.ReactNode; - actions: React.ReactNode[]; - previewModes?: PreviewMode[]; -} - -const ActionMenu: FunctionComponent = ({ - defaultAction, - actions, - previewModes -}) => { - const wrappedActions = actions.map(action =>
  • {action}
  • ); - - return ( - - ); -}; - -export default ActionMenu; diff --git a/wagtail_localize/static_src/legacy/common/components/Avatar/index.tsx b/wagtail_localize/static_src/legacy/common/components/Avatar/index.tsx deleted file mode 100644 index 492dd6e0..00000000 --- a/wagtail_localize/static_src/legacy/common/components/Avatar/index.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React, { FunctionComponent } from 'react'; - -declare var $: any; - -interface AvatarProps { - username: string; - avatarUrl: string; -} - -const Avatar: FunctionComponent = ({ username, avatarUrl }) => { - const ref = React.useRef(null); - - React.useEffect(() => { - // Activate tooltip - if (ref.current) { - $(ref.current).tooltip({ - animation: false, - title: function() { - return username; - }, - trigger: 'hover', - placement: 'bottom' - }); - } - }, [ref]); - - return ( - - {username} - - ); -}; - -export default Avatar; diff --git a/wagtail_localize/static_src/legacy/common/components/DocumentChooser/index.tsx b/wagtail_localize/static_src/legacy/common/components/DocumentChooser/index.tsx deleted file mode 100644 index fc02bdc0..00000000 --- a/wagtail_localize/static_src/legacy/common/components/DocumentChooser/index.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -interface DocumentAPI { - id: number; - title: string; -} - -interface DocumentChooserProps { - adminBaseUrl: string; - documentId: number | null; -} - -const DocumentChooser: FunctionComponent = ({ - adminBaseUrl, - documentId -}) => { - const [documentInfo, setDocumentInfo] = React.useState( - null - ); - - React.useEffect(() => { - setDocumentInfo(null); - - if (documentId) { - fetch(`${adminBaseUrl}api/main/documents/${documentId}/`) - .then(response => response.json()) - .then(setDocumentInfo); - } - }, [documentId]); - - // Render - let classNames = ['chooser', 'document-chooser']; - let inner; - if (documentId) { - if (documentInfo) { - inner = ( -
    - {documentInfo.title} - - -
    - ); - } else { - inner =

    {gettext('Fetching document information...')}

    ; - } - } else { - classNames.push('blank'); - - inner = ( -
    - -
    - ); - } - - return
    {inner}
    ; -}; - -export default DocumentChooser; diff --git a/wagtail_localize/static_src/legacy/common/components/Header/index.tsx b/wagtail_localize/static_src/legacy/common/components/Header/index.tsx deleted file mode 100644 index bb6fdbcd..00000000 --- a/wagtail_localize/static_src/legacy/common/components/Header/index.tsx +++ /dev/null @@ -1,317 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import Icon from '../Icon'; -import gettext from 'gettext'; -import styled from 'styled-components'; - -const StyledHeader = styled.header` - padding-inline-end: 20px; - padding-inline-start: 20px; - background-color: var(--color-primary); - color: #fff; - - @media screen and (min-width: 50em) { - padding-inline-end: 50px; - padding-inline-start: 50px; - } - - a { - text-decoration: none; - } -`; - -const StyledHeaderTitle = styled.h1` - color: #fff; - font-weight: 700; -`; - -const StyledButtonLink = styled.a` - &.button--live { - background-color: #fff; - color: var(--color-primary); - border-radius: 2px; - font-size: 14px; - font-weight: 600; - line-height: 2.3em; - padding: 0 0.75em; - - .icon { - width: 1.25em; - height: 1.25em; - vertical-align: text-top; - margin-right: 0.25em; - } - } -`; - -interface HeaderButtonActionProps { - label: string; - onClick: () => void; - title?: string; - classes?: string[]; - icon?: string; -} - -export const HeaderButtonAction: FunctionComponent = ({ - label, - onClick, - title, - classes, - icon -}) => { - let classNames = ['button']; - - if (classes) { - classNames = classNames.concat(classes); - } - - return ( - - ); -}; - -interface HeaderLinkActionProps { - label: string; - href: string; - title?: string; - classes?: string[]; - icon?: string; -} - -export const HeaderLinkAction: FunctionComponent = ({ - label, - href, - title, - classes, - icon -}) => { - let classNames = ['button']; - - if (classes) { - classNames = classNames.concat(classes); - } - - return ( - - {icon && } {label} - - ); -}; - -interface HeaderMetaProps { - name: string; - value: string | React.ReactFragment; - icon?: string; -} - -export const HeaderMeta: FunctionComponent = ({ - name, - value, - icon -}) => { - return ( -
  • - {icon && } {value} -
  • - ); -}; - -interface HeaderDropdownLinkOption { - label: string; - href: string; -} - -interface HeaderMetaDropdownProps { - name: string; - label: string; - options: HeaderDropdownLinkOption[]; - icon?: string; - title?: string; - classes?: string[]; -} - -export const HeaderMetaDropdown: FunctionComponent = ({ - name, - label, - options, - icon, - title, - classes -}) => { - let classNames = ['c-dropdown', 't-inverted']; - - if (classes) { - classNames = classNames.concat(classes); - } - - let items = options.map(({ label, href }) => { - return ( -
  • - - {label} - -
  • - ); - }); - - return ( - - - {label} -
    - - -
    -
    -
    -
      - {items} -
    -
    -
    - } - /> - ); -}; - -export interface BreadcrumbItem { - id: number; - isRoot: boolean; - title: string; - exploreUrl: string; -} - -interface HeaderProps { - title: string; - subtitle?: string; - breadcrumb?: BreadcrumbItem[]; - icon?: string; - merged?: boolean; - tabbed?: boolean; - actions?: React.ReactNode; - meta?: React.ReactNode; -} - -const Header: FunctionComponent = ({ - title, - subtitle, - breadcrumb, - icon, - merged, - tabbed, - actions, - meta -}) => { - let classNames = []; - let rowClassNames = ['row']; - - if (merged) { - classNames.push('merged'); - } - - if (tabbed) { - classNames.push('tab-merged'); - } else { - rowClassNames.push('nice-padding'); - } - - // Wrap subtitle with - let subtitleWrapped = <>; - if (subtitle) { - subtitleWrapped = {subtitle}; - } - - let breadcrumbRendered = <>; - if (breadcrumb && breadcrumb.length > 0) { - let breadcrumbFirst = true; - breadcrumbRendered = ( - - ); - } - - return ( - - {breadcrumbRendered} -
    - - {' '} - {/* TODO: Move style */} - {icon && } - {title} {subtitleWrapped} - -
    {actions}
    -
    -
      {meta}
    -
    - ); -}; - -export default Header; diff --git a/wagtail_localize/static_src/legacy/common/components/Icon/index.tsx b/wagtail_localize/static_src/legacy/common/components/Icon/index.tsx deleted file mode 100644 index be09e040..00000000 --- a/wagtail_localize/static_src/legacy/common/components/Icon/index.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React, { FunctionComponent } from 'react'; - -interface IconProps { - name: string; - className?: string; - title?: string; -} - -const Icon: FunctionComponent = ({ name, className, title }) => { - return ( - <> - - {title ? {title} : null} - - ); -}; - -export default Icon; diff --git a/wagtail_localize/static_src/legacy/common/components/ImageChooser/index.tsx b/wagtail_localize/static_src/legacy/common/components/ImageChooser/index.tsx deleted file mode 100644 index ba8115a5..00000000 --- a/wagtail_localize/static_src/legacy/common/components/ImageChooser/index.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -interface ImageAPI { - id: number; - title: string; - thumbnail: { - url: string; - width: number; - height: number; - }; -} - -interface ImageChooserProps { - adminBaseUrl: string; - imageId: number | null; -} - -const ImageChooser: FunctionComponent = ({ - adminBaseUrl, - imageId -}) => { - const [imageInfo, setImageInfo] = React.useState(null); - - React.useEffect(() => { - setImageInfo(null); - - if (imageId) { - fetch(`${adminBaseUrl}api/main/images/${imageId}/`) - .then(response => response.json()) - .then(setImageInfo); - } - }, [imageId]); - - // Render - let classNames = ['chooser', 'image-chooser']; - let inner; - if (imageId) { - if (imageInfo) { - inner = ( - - ); - } else { - inner =

    {gettext('Fetching image information...')}

    ; - } - } else { - classNames.push('blank'); - - inner = ( -
    - -
    - ); - } - - return
    {inner}
    ; -}; - -export default ImageChooser; diff --git a/wagtail_localize/static_src/legacy/common/components/PageChooser/index.tsx b/wagtail_localize/static_src/legacy/common/components/PageChooser/index.tsx deleted file mode 100644 index 0026abbf..00000000 --- a/wagtail_localize/static_src/legacy/common/components/PageChooser/index.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -interface PageAPI { - id: number; - title: string; -} - -interface PageChooserProps { - adminBaseUrl: string; - pageId: number | null; -} - -const PageChooser: FunctionComponent = ({ - adminBaseUrl, - pageId -}) => { - const [pageInfo, setPageInfo] = React.useState(null); - - React.useEffect(() => { - setPageInfo(null); - - if (pageId) { - fetch(`${adminBaseUrl}api/main/pages/${pageId}/`) - .then(response => response.json()) - .then(setPageInfo); - } - }, [pageId]); - - // Render - let classNames = ['chooser', 'page-chooser']; - let inner; - if (pageId) { - if (pageInfo) { - inner = ( -
    - {pageInfo.title} - - -
    - ); - } else { - inner =

    {gettext('Fetching page information...')}

    ; - } - } else { - classNames.push('blank'); - - inner = ( -
    - -
    - ); - } - - return
    {inner}
    ; -}; - -export default PageChooser; diff --git a/wagtail_localize/static_src/legacy/common/components/Section/index.tsx b/wagtail_localize/static_src/legacy/common/components/Section/index.tsx deleted file mode 100644 index c40a0765..00000000 --- a/wagtail_localize/static_src/legacy/common/components/Section/index.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import styled from 'styled-components'; - -const Title = styled.div` - box-sizing: border-box; - height: 40px; - -webkit-font-smoothing: auto; - background: #fcf2f2; - color: #200200; - text-transform: uppercase; - padding: 0.9em 0 0.9em 5em; - font-size: 0.95em; - margin: 0; - line-height: 1.5em; - font-weight: 400; - overflow: hidden; - position: relative; - - > h3 { - display: inline; - text-transform: inherit; - font-weight: inherit; - float: none; - color: inherit; - font-size: inherit; - } - - &::before { - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - text-shadow: none; - font-family: wagtail; - text-transform: none; - content: ''; - text-align: center; - display: block; - position: absolute; - z-index: 2; - font-size: 2em; - top: 0; - line-height: 1.8em; - left: 0; - width: 50px; - color: #fff; - padding: 0; - margin: 0; - background-color: #f37e77; - } -`; - -interface SectionProps { - title: string; -} - -const Section: FunctionComponent = ({ title, children }) => { - return ( -
    - - <h3>{title}</h3> - - {children} -
    - ); -}; - -export default Section; diff --git a/wagtail_localize/static_src/legacy/common/components/SnippetChooser/index.tsx b/wagtail_localize/static_src/legacy/common/components/SnippetChooser/index.tsx deleted file mode 100644 index ce6ef379..00000000 --- a/wagtail_localize/static_src/legacy/common/components/SnippetChooser/index.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -interface SnippetAPI { - id: string | number; - title: string; - edit_url: string; -} - -interface SnippetChooserProps { - adminBaseUrl: string; - snippetModel: { - app_label: string; - model_name: string; - verbose_name: string; - verbose_name_plural: string; - }; - snippetId: string | number | null; -} - -const SnippetChooser: FunctionComponent = ({ - adminBaseUrl, - snippetModel, - snippetId -}) => { - const [snippetInfo, setSnippetInfo] = React.useState( - null - ); - - React.useEffect(() => { - setSnippetInfo(null); - - if (snippetId) { - fetch( - `${adminBaseUrl}localize/api/snippets/${snippetModel.app_label}/${snippetModel.model_name}/${snippetId}/` - ) - .then(response => response.json()) - .then(setSnippetInfo); - } - }, [snippetId]); - - // Render - let classNames = ['chooser', 'snippet-chooser']; - let inner; - if (snippetId) { - if (snippetInfo) { - inner = ( - - ); - } else { - inner = ( -

    - {gettext('Fetching %s information...').replace( - '%s', - snippetModel.verbose_name - )} -

    - ); - } - } else { - classNames.push('blank'); - - inner = ( -
    - -
    - ); - } - - return
    {inner}
    ; -}; - -export default SnippetChooser; diff --git a/wagtail_localize/static_src/legacy/common/components/Tabs/index.tsx b/wagtail_localize/static_src/legacy/common/components/Tabs/index.tsx deleted file mode 100644 index f3548e6e..00000000 --- a/wagtail_localize/static_src/legacy/common/components/Tabs/index.tsx +++ /dev/null @@ -1,147 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import styled from 'styled-components'; - -const CurrentTabContext = React.createContext(''); - -export interface Tab { - label: string; - slug: string; - numErrors?: number; -} - -export interface TabsProps { - tabs: Tab[]; -} - -// Remove bottom margin that Wagtail adds by default -// This makes it tricky to align the toolbox consistently when there are both tabs and no tabs -const StyledTabs = styled.ul` - margin-bottom: 0; - margin-top: 0; - background-color: var(--color-primary); - - > li { - list-style-type: none; - width: 33%; - float: left; - padding: 0; - position: relative; - margin-right: 2px; - - @media screen and (min-width: 50em) { - width: auto; - padding: 0; - } - - &:first-of-type { - margin-left: 0; - } - - > a { - background-color: var(--color-primary-darker); - text-transform: uppercase; - font-weight: 600; - text-decoration: none; - display: block; - padding: 0.6em 0.7em 0.8em; - color: #fff; - border-top: 0.3em solid var(--color-primary-darker); - max-height: 1.44em; - overflow: hidden; - - @media screen and (min-width: 50em) { - padding-left: 20px; - padding-right: 20px; - } - } - - &.active > a { - box-shadow: none; - color: #333; - background-color: #fff; - border-top: 0.3em solid #333; - } - } - - &:before, - &:after { - content: ' '; - display: table; - } - - &:after { - clear: both; - } -`; - -export const Tabs: FunctionComponent = ({ tabs, children }) => { - const [currentTab, setCurrentTab] = React.useState(tabs[0].slug); - - return ( - <> - - {tabs.map(tab => { - const onClick = ( - e: React.MouseEvent - ) => { - e.preventDefault(); - setCurrentTab(tab.slug); - }; - - const classNames = []; - - if (tab.slug === currentTab) { - classNames.push('active'); - } - - if (tab.numErrors) { - classNames.push('errors'); - } - - return ( -
  • - - {tab.label} - -
  • - ); - })} -
    -
    - - {children} - -
    - - ); -}; - -// Remove top padding that Wagtail adds by default -// This makes it tricky to align the toolbox consistently when there are both tabs and no tabs -const SectionWithoutPadding = styled.section` - padding-top: 0 !important; -`; - -export const TabContent: FunctionComponent = ({ slug, children }) => { - const currentTab = React.useContext(CurrentTabContext); - - return ( - - ); -}; diff --git a/wagtail_localize/static_src/legacy/component_form/main.css b/wagtail_localize/static_src/legacy/component_form/main.css deleted file mode 100644 index 4f79087d..00000000 --- a/wagtail_localize/static_src/legacy/component_form/main.css +++ /dev/null @@ -1,42 +0,0 @@ -/* Put a box around component forms */ -.component-form { - border: 1px solid #ccc; - border-radius: 5px; - padding: 10px; - margin-top: 10px; - margin-bottom: 20px; -} - -/* Align component form buttons to the right */ -.component-form button { - float: right; -} -.component-form::after { - content: ' '; - display: table; - clear: both; -} - -/* Hide the enabled checkbox */ -.component-form__fieldname-enabled { - display: none; -} - -/* Hide fields if the form is disabled */ -.component-form--disabled .component-form__fields { - display: none; -} - -/* Show enabled button if the form is disabled */ -.component-form__enable-button { - display: none; -} - -.component-form--disabled .component-form__enable-button { - display: block; -} - -/* Hide disabled button if the form is disabled */ -.component-form--disabled .component-form__disable-button { - display: none; -} diff --git a/wagtail_localize/static_src/legacy/component_form/main.tsx b/wagtail_localize/static_src/legacy/component_form/main.tsx deleted file mode 100644 index 976b7579..00000000 --- a/wagtail_localize/static_src/legacy/component_form/main.tsx +++ /dev/null @@ -1,37 +0,0 @@ -document.addEventListener('DOMContentLoaded', () => { - const toggleInput = (trigger: Element, isChecked: boolean) => { - const componentForm = trigger.closest('.component-form'); - if (!componentForm) { - return; - } - if (isChecked) { - componentForm.classList.remove('component-form--disabled'); - } else { - componentForm.classList.add('component-form--disabled'); - } - - const enableInput = componentForm.querySelector( - '.component-form__fieldname-enabled input' - ) as HTMLInputElement | null; - if (enableInput) { - enableInput.checked = isChecked; - } - }; - // Component enable buttons - document - .querySelectorAll('.component-form__enable-button') - .forEach(enableButton => { - enableButton.addEventListener('click', () => { - toggleInput(enableButton, true); - }); - }); - - // Component disable buttons - document - .querySelectorAll('.component-form__disable-button') - .forEach(disableButton => { - disableButton.addEventListener('click', () => { - toggleInput(disableButton, false); - }); - }); -}); diff --git a/wagtail_localize/static_src/legacy/custom.d.ts b/wagtail_localize/static_src/legacy/custom.d.ts deleted file mode 100644 index 991306d2..00000000 --- a/wagtail_localize/static_src/legacy/custom.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare module '*.svg' { - const content: any; - export default content; -} - -declare module 'gettext' { - export default function gettext(text: string): string; -} diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/cloud-solid.svg b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/cloud-solid.svg deleted file mode 100644 index 02229b49..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/cloud-solid.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx deleted file mode 100644 index d83fa47a..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/footer.tsx +++ /dev/null @@ -1,158 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -import Icon from '../../../common/components/Icon'; -import ActionMenu from '../../../common/components/ActionMenu'; - -import { EditorProps } from '.'; - -const EditorFooter: FunctionComponent = ({ - csrfToken, - object: { isLocked }, - perms, - links, - previewModes, - locale -}) => { - let actions = [ -
    - - - - -
    - ]; - - if (links.convertToAliasUrl) { - actions.push( -
    - - - -
    - ); - } - - if (perms.canDelete) { - actions.push( - - - {gettext('Delete')} - - ); - } - - if (perms.canLock && !isLocked) { - actions.push( -
    - - - - -
    - ); - } - - if (perms.canUnlock && isLocked) { - actions.push( -
    - - - - -
    - ); - } - - if (perms.canUnpublish) { - actions.push( - - - {gettext('Unpublish')} - - ); - } - - if (perms.canPublish) { - actions.push( -
    - - - - -
    - ); - } - - // Make last action the default - const defaultAction = actions.pop(); - - return ( -
    -
      -
    • - -
    • -
    -
    - ); -}; - -export default EditorFooter; diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/header.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/header.tsx deleted file mode 100644 index 180c39f7..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/header.tsx +++ /dev/null @@ -1,191 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import gettext from 'gettext'; - -import Avatar from '../../../common/components/Avatar'; - -import Header, { - HeaderLinkAction, - HeaderMeta -} from '../../../common/components/Header'; - -import { EditorProps, Locale, Translation } from '.'; -import { EditorState } from './reducer'; -import Icon from '../../../common/components/Icon'; - -interface LocaleMetaProps { - name: string; - sourceLocale: Locale; - targetLocale: Locale; - translations: Translation[]; -} - -const LocaleMeta: FunctionComponent = ({ - name, - translations, - sourceLocale, - targetLocale -}) => { - // Render source - const sourceTranslation = translations - .filter(({ locale }) => locale.code == sourceLocale.code) - .pop(); - let sourceRendered = - sourceTranslation && sourceTranslation.editUrl ? ( - - {sourceLocale.displayName} - - ) : ( - <>{sourceLocale.displayName} - ); - - // Render target - let targetRendered = <>; - - let translationOptions = translations - .filter(({ locale }) => locale.code != sourceLocale.code) - .map(({ locale, editUrl }) => { - return { - label: locale.displayName, - href: editUrl - }; - }); - - if (translationOptions.length > 0) { - let items = translationOptions.map(({ label, href }) => { - return ( -
  • - - {label} - -
  • - ); - }); - - targetRendered = ( - - ); - } else { - targetRendered = <>{targetLocale.displayName}; - } - - return ( -
  • - {sourceRendered} - - {targetRendered} -
  • - ); -}; - -interface EditorHeaderProps extends EditorProps, EditorState {} - -const EditorHeader: FunctionComponent = ({ - object, - breadcrumb, - sourceLocale, - locale, - translations, - stringTranslations -}) => { - // Build actions - let actions = []; - if (object.isLive && object.liveUrl) { - actions.push( - - ); - } - - let status = <>; - if (object.isLive) { - if (object.lastPublishedDate) { - status = <>{gettext('Published on ') + object.lastPublishedDate}; - } else { - status = <>{gettext('Published')}; - } - - if (object.lastPublishedBy && object.lastPublishedBy.avatar_url) { - status = ( - <> - - {status} - - ); - } - } else { - status = <>{gettext('Draft')}; - } - - // Meta - let meta = [ - , - - ]; - - // Title - // Allow the title to be overridden by the segment that represents the "title" field on Pages. - let title = object.title; - if (object.titleSegmentId) { - Array.from(stringTranslations.entries()).forEach( - ([segmentId, stringTranslation]) => { - if (segmentId == object.titleSegmentId) { - title = stringTranslation.value; - } - } - ); - } - - return ( -
    - ); -}; - -export default EditorHeader; diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/index.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/index.tsx deleted file mode 100644 index 1889afd9..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/index.tsx +++ /dev/null @@ -1,323 +0,0 @@ -import React, { FunctionComponent, useEffect } from 'react'; - -import Section from '../../../common/components/Section'; -import { Tabs, TabContent } from '../../../common/components/Tabs'; - -import { EditorState, reducer } from './reducer'; -import EditorHeader from './header'; -import EditorFooter from './footer'; -import EditorSegmentList from './segments'; -import EditorToolbox from './toolbox'; -import gettext from 'gettext'; - -export interface User { - full_name: string; - avatar_url: string | null; -} - -export interface Tab { - label: string; - slug: string; -} - -export interface Locale { - code: string; - displayName: string; -} - -export interface BreadcrumbItem { - id: number; - isRoot: boolean; - title: string; - exploreUrl: string; -} - -export interface Translation { - title: string; - locale: Locale; - editUrl?: string; -} - -export interface PreviewMode { - mode: string; - label: string; - url: string; -} - -export interface PageChooserWidget { - type: 'page_chooser'; - allowed_page_types: string[]; -} - -export interface SnippetChooserWidget { - type: 'snippet_chooser'; - snippet_model: { - app_label: string; - model_name: string; - verbose_name: string; - verbose_name_plural: string; - }; - chooser_url: string; -} - -export interface OtherWidgets { - type: 'text' | 'image_chooser' | 'document_chooser' | 'unknown'; -} - -export interface SegmentCommon { - id: number; - contentPath: string; - location: { - tab: string; - field: string; - blockId: string | null; - subField: string | null; - helpText: string; - widget: PageChooserWidget | SnippetChooserWidget | OtherWidgets; - }; -} - -export interface StringSegment extends SegmentCommon { - type: 'string'; - source: string; - editUrl: string; -} - -export interface SynchronisedValueSegment extends SegmentCommon { - type: 'synchronised_value'; - value: any; - editUrl: string; -} - -export interface RelatedObjectSegment extends SegmentCommon { - type: 'related_object'; - source: { - title: string; - isLive: boolean; - liveUrl?: string; - editUrl?: string; - createTranslationRequestUrl?: string; - } | null; - dest: { - title: string; - isLive: boolean; - liveUrl?: string; - editUrl?: string; - } | null; - translationProgress: { - totalSegments: number; - translatedSegments: number; - } | null; // Null if translated without wagtail-localize -} - -export type Segment = - | StringSegment - | SynchronisedValueSegment - | RelatedObjectSegment; - -export interface StringTranslationAPI { - string_id: number; - segment_id: number; - data: string; - error: string; - comment: string; - last_translated_by: User | null; -} - -export interface StringTranslation { - value: string; - isSaving: boolean; - isErrored: boolean; - comment: string; - translatedBy: User | null; -} - -export interface SegmentOverrideAPI { - segment_id: number; - data: any; - error: string; -} - -export interface SegmentOverride { - value: any; - isSaving: boolean; - isErrored: boolean; - comment: string; -} - -export interface EditorProps { - has_legacy_styling: boolean; - adminBaseUrl: string; - csrfToken: string; - object: { - title: string; - titleSegmentId: number | null; - isLive: boolean; - isLocked: boolean; - lastPublishedDate: string | null; - lastPublishedBy: User | null; - liveUrl?: string; - }; - breadcrumb: BreadcrumbItem[]; - tabs: Tab[]; - sourceLocale: Locale; - locale: Locale; - translations: Translation[]; - perms: { - canSaveDraft: boolean; - canPublish: boolean; - canUnpublish: boolean; - canLock: boolean; - canUnlock: boolean; - canDelete: boolean; - }; - links: { - downloadPofile: string; - uploadPofile: string; - unpublishUrl: string; - lockUrl: string; - unlockUrl: string; - deleteUrl: string; - stopTranslationUrl: string; - convertToAliasUrl: string; - }; - previewModes: PreviewMode[]; - machineTranslator: { - name: string; - url: string; - } | null; - segments: Segment[]; - initialStringTranslations: StringTranslationAPI[]; - initialOverrides: SegmentOverrideAPI[]; -} - -const TranslationEditor: FunctionComponent = props => { - // Convert initialStringTranslations into a Map that maps segment ID to translation info - const stringTranslations: Map = new Map(); - props.initialStringTranslations.forEach(translation => { - stringTranslations.set(translation.segment_id, { - value: translation.data, - isSaving: false, - isErrored: !!translation.error, - comment: translation.error - ? translation.error - : translation.comment, - translatedBy: translation.last_translated_by - }); - }); - - // Same with initialSegmentOverrides - const segmentOverrides: Map = new Map(); - props.initialOverrides.forEach(override => { - segmentOverrides.set(override.segment_id, { - value: override.data, - isSaving: false, - isErrored: !!override.error, - comment: override.error || gettext('Changed') - }); - }); - - // Set up initial state - const initialState: EditorState = { - stringTranslations, - segmentOverrides, - editingSegments: new Set() - }; - - const [state, dispatch] = React.useReducer(reducer, initialState); - - // Catch user trying to navigate away with unsaved segments - useEffect(() => { - if (state.editingSegments.size > 0) { - const onUnload = (event: BeforeUnloadEvent) => { - const confirmationMessage = gettext( - 'There are unsaved segments. Please save or cancel them before leaving.' - ); - - // eslint-disable-next-line no-param-reassign - event.returnValue = confirmationMessage; - return confirmationMessage; - }; - - window.addEventListener('beforeunload', onUnload); - return () => { - window.removeEventListener('beforeunload', onUnload); - }; - } - }, [state.editingSegments]); - - const tabData = props.tabs - .map(tab => { - const segments = props.segments.filter( - segment => segment.location.tab == tab.slug - ); - const translations = segments.map( - segment => - segment.type == 'string' && - state.stringTranslations.get(segment.id) - ); - - return { - numErrors: translations.filter( - translation => translation && translation.isErrored - ).length, - segments, - ...tab - }; - }) - .filter(tab => tab.segments.length > 0); - - let tabs = <>; - if (tabData.length > 1) { - tabs = ( - - {tabData.map(tab => { - return ( - - -
    - -
    -
    - ); - })} -
    - ); - } else { - tabs = ( - <> - -
    - -
    - - ); - } - - return ( - <> - - {tabs} - - - ); -}; - -export default TranslationEditor; diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/reducer.ts b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/reducer.ts deleted file mode 100644 index c910ed35..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/reducer.ts +++ /dev/null @@ -1,209 +0,0 @@ -import gettext from 'gettext'; - -import { - StringTranslationAPI, - StringTranslation, - SegmentOverride, - SegmentOverrideAPI -} from '.'; - -export interface EditorState { - stringTranslations: Map; - segmentOverrides: Map; - editingSegments: Set; -} - -export const SET_EDITING_MODE = 'set-editing-mode'; -export interface SetEditingModeAction { - type: typeof SET_EDITING_MODE; - segmentId: number; - editing: boolean; -} - -export const EDIT_STRING_TRANSLATION = 'edit-string-translation'; -export interface EditStringTranslationAction { - type: typeof EDIT_STRING_TRANSLATION; - segmentId: number; - value: string; -} - -export const TRANSLATION_SAVED = 'translation-saved'; -export interface TranslationSavedAction { - type: typeof TRANSLATION_SAVED; - segmentId: number; - translation: StringTranslationAPI; -} - -export const TRANSLATION_DELETED = 'translation-deleted'; -export interface TranslationDeletedAction { - type: typeof TRANSLATION_DELETED; - segmentId: number; -} - -export const TRANSLATION_SAVE_SERVER_ERROR = 'translation-save-server-error'; -export interface TranslationSaveServerErrorAction { - type: typeof TRANSLATION_SAVE_SERVER_ERROR; - segmentId: number; -} - -export const EDIT_OVERRIDE = 'edit-override'; -export interface EditOverrideAction { - type: typeof EDIT_OVERRIDE; - segmentId: number; - value: any; -} - -export const DELETE_OVERRIDE = 'delete-override'; -export interface DeleteOverrideAction { - type: typeof DELETE_OVERRIDE; - segmentId: number; -} - -export const OVERRIDE_SAVED = 'override-saved'; -export interface OverrideSavedAction { - type: typeof OVERRIDE_SAVED; - segmentId: number; - override: SegmentOverrideAPI; -} - -export const OVERRIDE_DELETED = 'override-deleted'; -export interface OverrideDeletedAction { - type: typeof OVERRIDE_DELETED; - segmentId: number; -} - -export const OVERRIDE_SAVE_SERVER_ERROR = 'override-save-server-error'; -export interface OverrideSaveServerErrorAction { - type: typeof OVERRIDE_SAVE_SERVER_ERROR; - segmentId: number; -} - -export type EditorAction = - | SetEditingModeAction - | EditStringTranslationAction - | TranslationSavedAction - | TranslationDeletedAction - | TranslationSaveServerErrorAction - | EditOverrideAction - | DeleteOverrideAction - | OverrideSavedAction - | OverrideDeletedAction - | OverrideSaveServerErrorAction; - -export function reducer(state: EditorState, action: EditorAction) { - let stringTranslations = new Map(state.stringTranslations); - let segmentOverrides = new Map(state.segmentOverrides); - let editingSegments = new Set(state.editingSegments); - - switch (action.type) { - // Editing mode - case SET_EDITING_MODE: { - if (action.editing) { - editingSegments.add(action.segmentId); - } else { - editingSegments.delete(action.segmentId); - } - break; - } - - // Translation actions - case EDIT_STRING_TRANSLATION: { - stringTranslations.set(action.segmentId, { - value: action.value, - isSaving: true, - isErrored: false, - comment: gettext('Saving...'), - translatedBy: null - }); - break; - } - case TRANSLATION_SAVED: { - stringTranslations.set(action.segmentId, { - value: action.translation.data, - isSaving: false, - isErrored: !!action.translation.error, - comment: action.translation.error - ? action.translation.error - : action.translation.comment, - translatedBy: action.translation.last_translated_by - }); - break; - } - case TRANSLATION_DELETED: { - stringTranslations.delete(action.segmentId); - break; - } - case TRANSLATION_SAVE_SERVER_ERROR: { - const translation = stringTranslations.get(action.segmentId); - - if (translation) { - stringTranslations.set( - action.segmentId, - Object.assign({}, translation, { - isSaving: false, - isErrored: true, - comment: gettext('Server error') - }) - ); - } - break; - } - - // Override actions - - case EDIT_OVERRIDE: { - segmentOverrides.set(action.segmentId, { - value: action.value, - isSaving: true, - isErrored: false, - comment: gettext('Changed') - }); - break; - } - case DELETE_OVERRIDE: { - const override = segmentOverrides.get(action.segmentId); - - if (override) { - segmentOverrides.set( - action.segmentId, - Object.assign({}, override, { - isSaving: true - }) - ); - } - break; - } - case OVERRIDE_SAVED: { - segmentOverrides.set(action.segmentId, { - value: action.override.data, - isSaving: false, - isErrored: !!action.override.error, - comment: action.override.error || gettext('Changed') - }); - break; - } - case OVERRIDE_DELETED: { - segmentOverrides.delete(action.segmentId); - break; - } - case OVERRIDE_SAVE_SERVER_ERROR: { - const override = segmentOverrides.get(action.segmentId); - - if (override) { - segmentOverrides.set( - action.segmentId, - Object.assign({}, override, { - isSaving: false - }) - ); - } - break; - } - } - - return Object.assign({}, state, { - stringTranslations, - segmentOverrides, - editingSegments - }); -} diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/segments.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/segments.tsx deleted file mode 100644 index 15a16cf2..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/segments.tsx +++ /dev/null @@ -1,963 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import styled from 'styled-components'; -import gettext from 'gettext'; - -import Icon from '../../../common/components/Icon'; -import Avatar from '../../../common/components/Avatar'; - -import PageChooser from '../../../common/components/PageChooser'; -import ImageChooser from '../../../common/components/ImageChooser'; -import DocumentChooser from '../../../common/components/DocumentChooser'; -import SnippetChooser from '../../../common/components/SnippetChooser'; - -import { - EditorProps, - StringSegment, - SynchronisedValueSegment, - Segment, - StringTranslation, - StringTranslationAPI, - SegmentOverride, - SegmentOverrideAPI, - Locale, - RelatedObjectSegment -} from '.'; -import { - EditorState, - EditorAction, - EDIT_STRING_TRANSLATION, - TRANSLATION_SAVE_SERVER_ERROR, - TRANSLATION_SAVED, - TRANSLATION_DELETED, - EDIT_OVERRIDE, - OVERRIDE_SAVED, - OVERRIDE_SAVE_SERVER_ERROR, - DELETE_OVERRIDE, - OVERRIDE_DELETED -} from './reducer'; - -function saveTranslation( - segment: StringSegment, - value: string, - csrfToken: string, - dispatch: React.Dispatch -) { - dispatch({ - type: EDIT_STRING_TRANSLATION, - segmentId: segment.id, - value: value - }); - if (value) { - // Create/update the translation - const formData = new FormData(); - formData.append('value', value); - - fetch(segment.editUrl, { - credentials: 'same-origin', - method: 'PUT', - body: formData, - headers: { - 'X-CSRFToken': csrfToken - } - }) - .then(response => { - if (response.status == 200 || response.status == 201) { - return response.json(); - } else { - throw new Error('Unrecognised HTTP status returned'); - } - }) - .then((translation: StringTranslationAPI) => { - dispatch({ - type: TRANSLATION_SAVED, - segmentId: segment.id, - translation - }); - }) - .catch(() => { - dispatch({ - type: TRANSLATION_SAVE_SERVER_ERROR, - segmentId: segment.id - }); - }); - } else { - // Delete the translation - fetch(segment.editUrl, { - credentials: 'same-origin', - method: 'DELETE', - headers: { - 'X-CSRFToken': csrfToken - } - }).then(response => { - if (response.status == 200 || response.status == 404) { - dispatch({ - type: TRANSLATION_DELETED, - segmentId: segment.id - }); - } else { - dispatch({ - type: TRANSLATION_SAVE_SERVER_ERROR, - segmentId: segment.id - }); - } - }); - } -} - -function saveOverride( - segment: SynchronisedValueSegment, - value: any, - csrfToken: string, - dispatch: React.Dispatch -) { - dispatch({ - type: EDIT_OVERRIDE, - segmentId: segment.id, - value: value - }); - - // Create/update the translation - const formData = new FormData(); - formData.append('value', value); - - fetch(segment.editUrl, { - credentials: 'same-origin', - method: 'PUT', - body: formData, - headers: { - 'X-CSRFToken': csrfToken - } - }) - .then(response => { - if (response.status == 200 || response.status == 201) { - return response.json(); - } else { - throw new Error('Unrecognised HTTP status returned'); - } - }) - .then((override: SegmentOverrideAPI) => { - dispatch({ - type: OVERRIDE_SAVED, - segmentId: segment.id, - override - }); - }) - .catch(() => { - dispatch({ - type: OVERRIDE_SAVE_SERVER_ERROR, - segmentId: segment.id - }); - }); -} - -function deleteOverride( - segment: SynchronisedValueSegment, - csrfToken: string, - dispatch: React.Dispatch -) { - dispatch({ - type: DELETE_OVERRIDE, - segmentId: segment.id - }); - - // Delete the override - fetch(segment.editUrl, { - credentials: 'same-origin', - method: 'DELETE', - headers: { - 'X-CSRFToken': csrfToken - } - }).then(response => { - if (response.status == 200 || response.status == 404) { - dispatch({ - type: OVERRIDE_DELETED, - segmentId: segment.id - }); - } else { - dispatch({ - type: OVERRIDE_SAVE_SERVER_ERROR, - segmentId: segment.id - }); - } - }); -} - -interface SingleLineTextAreaProps { - value: string; - onChange?(newValue: string): void; - onHitEnter?(): void; - focusOnMount?: boolean; -} - -const StyledTextArea = styled.textarea` - border: none; - border-radius: 0; - resize: none; - white-space: normal; -`; - -const SingleLineTextArea: FunctionComponent = ({ - value, - onChange, - onHitEnter, - focusOnMount -}) => { - // Using a single line text area to get the wrapping behaviour we want. But it also allows the Grammarly plugin to work - - const onKeyDown = (e: React.KeyboardEvent) => { - if (e.key == 'Enter' && onHitEnter) { - e.preventDefault(); - onHitEnter(); - } - }; - - const onChangeValue = (e: React.ChangeEvent) => { - if (onChange) { - // Since we only want the wrapping behaviour and not newlines, we need to strip them out - onChange(e.target.value.replace(/(\r\n|\n|\r)/gm, '')); - } - }; - - // Resize the textarea whenever the value is changed - const textAreaElement = React.useRef(null); - React.useEffect(() => { - if (textAreaElement.current) { - textAreaElement.current.style.height = ''; - textAreaElement.current.style.height = - textAreaElement.current.scrollHeight + 'px'; - } - }, [value, textAreaElement]); - - // Focus the textarea when it is mounted - React.useEffect(() => { - if (focusOnMount && textAreaElement.current) { - textAreaElement.current.focus(); - } - }, [textAreaElement]); - - return ( - - ); -}; - -export const BlockLabel = styled.h3` - color: #007273; - border: 1px solid #f5f5f5; - padding-left: 11px; - padding-right: 11px; - padding-top: 7px; - padding-bottom: 9px; - display: inline-block; - margin-bottom: 0; - font-weight: bold; -`; - -const BlockSegments = styled.ul` - list-style-type: none; - border: 1px solid #eeeeee; - background-color: #f1f1f1; - padding: 0; - margin: 0; - - > li { - &.errored { - background-color: #fee7e8; - // !important required to override the border-bottom rule just below - border: 1px solid #cd3238 !important; - } - - &.incomplete { - // !important required to override the border-bottom rule just below - border-left: 5px solid #f37e77 !important; - } - - &.complete { - // !important required to override the border-bottom rule just below - border-left: 5px solid #007d7e !important; - } - - &:not(:last-child) { - border-bottom: 1px solid #eaeaea; - } - - &:after { - content: ''; - display: table; - clear: both; - } - } -`; - -const SegmentFieldLabel = styled.h4` - margin: 0; - padding: 15px 20px; - color: #007273; - font-style: normal; - font-weight: bold; - padding-left: 20px; -`; - -const SegmentSource = styled.p` - padding: 15px 20px; - font-style: italic; -`; - -const SegmentValue = styled.div` - padding: 0.9em 1.2em; - - > p, - > ${StyledTextArea} { - font-size: 1.2em; - font-style: italic; - line-height: 1.5em; - font-style: italic; - font-weight: 600; - } -`; - -const ActionButton = styled.button` - text-transform: uppercase; - font-size: 0.8em; - font-weight: bold; - color: #017373; - background-color: #e5f1f1; - border: 1px solid #6cafaf; - border-radius: 2px; - padding: 5px 10px; - - &:hover { - background-color: darken(#e5f1f1, 10%); - } -`; - -const SegmentToolbar = styled.ul` - box-sizing: border-box; - width: 100%; - text-align: right; - padding: 10px; - margin: 0; - - > li { - display: inline-block; - - &:not(:first-child) { - margin-left: 15px; - } - } - - .icon { - width: 1.3em; - height: 1.3em; - vertical-align: text-bottom; - margin-left: 10px; - - &--green { - color: #15704d; - } - - &--red { - color: #cd3239; - } - } -`; - -const SegmentList = styled.ul` - list-style-type: none; - padding-left: 50px; - padding-right: 50px; - max-width: 1200px; -`; - -interface EditorStringSegmentProps { - segment: StringSegment; - translation?: StringTranslation; - isLocked: boolean; - isEditing: boolean; - setIsEditing(editing: boolean): void; - dispatch: React.Dispatch; - csrfToken: string; -} - -const EditorStringSegment: FunctionComponent = ({ - segment, - translation, - isLocked, - isEditing, - setIsEditing, - dispatch, - csrfToken -}) => { - const [editingValue, setEditingValue] = React.useState( - (translation && translation.value) || '' - ); - - let comment = <>; - let buttons: React.ReactElement[] = []; - let value: React.ReactFragment = <>; - - if (isEditing && !isLocked) { - const onClickSave = () => { - setIsEditing(false); - saveTranslation(segment, editingValue, csrfToken, dispatch); - }; - - const onClickCancel = () => { - setIsEditing(false); - }; - - buttons = [ -
  • - - {gettext('Cancel')} - -
  • , -
  • - - {gettext('Save')} - -
  • - ]; - - value = ( - - ); - } else if (translation && translation.isSaving) { - comment = ( - <> - {gettext('Saving...')} - - ); - value =

    {translation && translation.value}

    ; - } else { - const onClickEdit = () => { - setIsEditing(true); - setEditingValue((translation && translation.value) || ''); - }; - - if (translation && translation.comment) { - comment = ( - <> - {translation.comment} - {translation.isErrored ? ( - - ) : ( - - )} - - ); - - if ( - translation.translatedBy && - translation.translatedBy.avatar_url - ) { - comment = ( - <> - - {comment} - - ); - } - } - - if (!isLocked) { - buttons.push( -
  • - - {translation ? gettext('Edit') : gettext('Translate')} - -
  • - ); - } - - value =

    {translation && translation.value}

    ; - } - - let className = 'complete'; - if (!translation) { - className = 'incomplete'; - } else if (translation.isErrored) { - className = 'errored'; - } - - return ( -
  • - {segment.location.subField && ( - - {segment.location.subField} - - )} - {segment.source} - {value} - -
  • {comment}
  • - {buttons} - - - ); -}; - -interface EditorSynchronisedValueSegmentProps { - adminBaseUrl: string; - segment: SynchronisedValueSegment; - override?: SegmentOverride; - sourceLocale: Locale; - isLocked: boolean; - isEditing: boolean; - setIsEditing(editing: boolean): void; - dispatch: React.Dispatch; - csrfToken: string; -} - -const EditorSynchronisedValueSegment: FunctionComponent< - EditorSynchronisedValueSegmentProps -> = ({ - adminBaseUrl, - segment, - override, - sourceLocale, - isLocked, - isEditing, - setIsEditing, - dispatch, - csrfToken -}) => { - let comment = <>; - let buttons: React.ReactFragment[] = []; - let value: React.ReactFragment = <>; - - if (override) { - comment = ( - <> - {override.comment} - {override.isErrored ? ( - - ) : ( - - )} - - ); - } else { - comment = ( - <> - {gettext('Uses %s version').replace( - '%s', - sourceLocale.displayName - )}{' '} - - - ); - } - - const widget = segment.location.widget; - if (widget.type == 'text') { - const [editingValue, setEditingValue] = React.useState( - (override && override.value) || segment.value - ); - - if (isEditing && !isLocked) { - const onClickSave = () => { - setIsEditing(false); - saveOverride(segment, editingValue, csrfToken, dispatch); - }; - - const onClickCancel = () => { - setIsEditing(false); - }; - - buttons = [ - - {gettext('Cancel')} - , - - {gettext('Save')} - - ]; - - value = ( - - ); - } else { - const onClickEdit = () => { - setIsEditing(true); - setEditingValue((override && override.value) || segment.value); - }; - - if (!isLocked) { - buttons.push( - - {gettext('Edit')} - - ); - } - - value =

    {(override && override.value) || segment.value}

    ; - } - } else if (widget.type == 'page_chooser') { - const onClickChangePage = () => { - (window as any).ModalWorkflow({ - url: (window as any).chooserUrls.pageChooser, - urlParams: { - page_type: widget.allowed_page_types.join(',') - }, - onload: (window as any).PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS, - responses: { - pageChosen: function(pageData: any) { - saveOverride(segment, pageData.id, csrfToken, dispatch); - } - } - }); - }; - if (!isLocked) { - buttons.push( - - {gettext('Change page')} - - ); - } - - value = ( - - ); - } else if (widget.type == 'image_chooser') { - const onClickChangeImage = () => { - (window as any).ModalWorkflow({ - url: (window as any).chooserUrls.imageChooser, - onload: (window as any).IMAGE_CHOOSER_MODAL_ONLOAD_HANDLERS, - responses: { - imageChosen: function(imageData: any) { - saveOverride( - segment, - imageData.id, - csrfToken, - dispatch - ); - } - } - }); - }; - if (!isLocked) { - buttons.push( - - {gettext('Change image')} - - ); - } - - value = ( - - ); - } else if (widget.type == 'document_chooser') { - const onClickChangeDocument = () => { - (window as any).ModalWorkflow({ - url: (window as any).chooserUrls.documentChooser, - onload: (window as any).DOCUMENT_CHOOSER_MODAL_ONLOAD_HANDLERS, - responses: { - documentChosen: function(documentData: any) { - saveOverride( - segment, - documentData.id, - csrfToken, - dispatch - ); - } - } - }); - }; - if (!isLocked) { - buttons.push( - - {gettext('Change document')} - - ); - } - - value = ( - - ); - } else if (widget.type == 'snippet_chooser') { - const onClickChangeSnippet = () => { - (window as any).ModalWorkflow({ - url: widget.chooser_url, - onload: (window as any).SNIPPET_CHOOSER_MODAL_ONLOAD_HANDLERS, - responses: { - snippetChosen: function(snippetData: any) { - saveOverride( - segment, - snippetData.id, - csrfToken, - dispatch - ); - } - } - }); - }; - if (!isLocked) { - buttons.push( - - {gettext('Change %s').replace( - '%s', - widget.snippet_model.verbose_name - )} - - ); - } - - value = ( - - ); - } else { - value =

    {segment.value}

    ; - } - - if (override) { - const onClickUseEnglishVersion = () => { - deleteOverride(segment, csrfToken, dispatch); - }; - buttons.push( - - {gettext('Revert to %s version').replace( - '%s', - sourceLocale.displayName - )} - - ); - } - - let className = ''; - if (override && override.isErrored) { - className = 'errored'; - } - - return ( -
  • - {segment.location.subField && ( - - {segment.location.subField} - - )} - {value} - -
  • {comment}
  • - {buttons.map(button => ( -
  • {button}
  • - ))} - - - ); -}; - -interface EditorRelatedObjectSegmentProps { - segment: RelatedObjectSegment; -} - -const EditorRelatedObjectSegment: FunctionComponent< - EditorRelatedObjectSegmentProps -> = ({ segment }) => { - const openEditUrl = () => { - if (segment.dest) { - window.open(segment.dest.editUrl); - } - }; - - const openCreateTranslationRequestUrl = () => { - if (!!segment.source && segment.source.createTranslationRequestUrl) { - window.open(segment.source.createTranslationRequestUrl); - } - }; - - let message = <>; - - if (segment.dest) { - if (segment.translationProgress !== null) { - // Translated with Wagtail localize. Show progress - message = ( - <> - {segment.translationProgress.translatedSegments} /{' '} - {segment.translationProgress.totalSegments}{' '} - {gettext('segments translated')} - {segment.translationProgress.translatedSegments == - segment.translationProgress.totalSegments && ( - - )} - - ); - } else { - // Segment translated without Wagtail localize. Just show a tick - message = ; - } - } else { - // Not translated - message = ( - <> - {gettext('Not translated')}{' '} - - - ); - } - - return ( -
  • - {segment.location.subField && ( - - {segment.location.subField} - - )} - -

    - {segment.source - ? segment.source.title - : gettext('[DELETED]')} -

    -
    - -
  • {message}
  • -
  • - {segment.dest && segment.dest.editUrl && ( - - {gettext('Edit')} - - )} - {!segment.dest && - !!segment.source && - segment.source.createTranslationRequestUrl && ( - - {gettext('Translate')} - - )} -
  • - - - ); -}; - -interface EditorSegmentListProps extends EditorProps, EditorState { - dispatch: React.Dispatch; - csrfToken: string; -} - -const EditorSegmentList: FunctionComponent = ({ - adminBaseUrl, - object: { isLocked }, - sourceLocale, - segments, - stringTranslations, - segmentOverrides, - editingSegments, - dispatch, - csrfToken -}) => { - // Group segments by field/block - const segmentsByFieldBlock: Map = new Map(); - segments.forEach(segment => { - const field = segment.location.field; - const blockId = segment.location.blockId || 'null'; - const key = `${field}/${blockId}`; - - let list = segmentsByFieldBlock.get(key); - if (!list) { - list = []; - segmentsByFieldBlock.set(key, list); - } - - list.push(segment); - }); - - const segmentRendered = Array.from(segmentsByFieldBlock.entries()).map( - ([fieldBlock, segments]) => { - const setEditingMode = (segmentId: number, editing: boolean) => { - dispatch({ - type: 'set-editing-mode', - segmentId, - editing - }); - }; - - // Render segments in field/block - const segmentsRendered = segments.map(segment => { - switch (segment.type) { - case 'string': { - return ( - - setEditingMode(segment.id, editing) - } - dispatch={dispatch} - csrfToken={csrfToken} - /> - ); - } - case 'synchronised_value': { - return ( - - setEditingMode(segment.id, editing) - } - dispatch={dispatch} - csrfToken={csrfToken} - /> - ); - } - case 'related_object': { - return ; - } - } - }); - - return ( -
  • - {segments[0].location.field} - {segmentsRendered} -
  • - ); - } - ); - - return {segmentRendered}; -}; - -export default EditorSegmentList; diff --git a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/toolbox.tsx b/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/toolbox.tsx deleted file mode 100644 index 02004c7f..00000000 --- a/wagtail_localize/static_src/legacy/editor/components/TranslationEditor/toolbox.tsx +++ /dev/null @@ -1,172 +0,0 @@ -import React, { FunctionComponent } from 'react'; -import styled from 'styled-components'; -import gettext from 'gettext'; - -import Icon from '../../../common/components/Icon'; - -import CloudIcon from './cloud-solid.svg'; - -import { EditorProps } from '.'; -import { EditorState, EditorAction } from './reducer'; - -const ToolboxWrapper = styled.div` - padding-top: 20px; - - &:after { - content: ''; - display: table; - clear: both; - } -`; - -const ToolWrapper = styled.div` - float: left; - margin-left: 50px; - margin-bottom: 20px; - min-height: 100px; -`; - -const HiddenFileInput = styled.input` - border: 0; - clip: rect(0 0 0 0); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - width: 1px; -`; - -const StyledCloudIcon = styled(CloudIcon)` - width: 1.5em; - height: 1.5em; - vertical-align: text-top; -`; - -interface EditorToolboxProps extends EditorProps, EditorState { - dispatch: React.Dispatch; - csrfToken: string; -} - -const EditorToolbox: FunctionComponent = ({ - object: { isLocked }, - links, - machineTranslator, - csrfToken, - stringTranslations, - segments -}) => { - if (isLocked) { - return <>; - } - - const hasUntranslatedSegments = - Array.from(stringTranslations.keys()).length < segments.length; - - const uploadPofileForm = React.useRef(null); - const uploadPofileFileInput = React.useRef(null); - - const onClickUploadPO = () => { - if (uploadPofileFileInput.current) { - uploadPofileFileInput.current.click(); - } - }; - - const uploadPofile = (e: React.ChangeEvent) => { - e.preventDefault(); - - if (uploadPofileForm.current) { - uploadPofileForm.current.submit(); - } - }; - - return ( - - -

    - {gettext('Download PO file and input translations offline')} -

    - - {gettext('Download PO file')} - -
    - - -

    - {gettext( - 'Upload translated PO file to submit translations' - )} -

    - -
    - - - - -
    - - {machineTranslator && ( - -

    - {gettext('Translate all missing strings with ') + - machineTranslator.name} -

    -
    - - - -
    -
    - )} -
    - ); -}; - -export default EditorToolbox; diff --git a/wagtail_localize/static_src/legacy/editor/main.tsx b/wagtail_localize/static_src/legacy/editor/main.tsx deleted file mode 100644 index ef945eef..00000000 --- a/wagtail_localize/static_src/legacy/editor/main.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; - -import TranslationEditor from './components/TranslationEditor'; - -document.addEventListener('DOMContentLoaded', () => { - const element = document.querySelector('.js-translation-editor'); - - if (element instanceof HTMLElement && element.dataset.props) { - const csrfTokenElement = element.querySelector( - '[name="csrfmiddlewaretoken"]' - ); - - if (csrfTokenElement instanceof HTMLInputElement) { - const csrfToken = csrfTokenElement.value; - - ReactDOM.render( - , - element - ); - } else { - console.error( - "Not starting translation editor because I couldn't find the CSRF token element!" - ); - } - } -}); diff --git a/wagtail_localize/static_src/legacy/main.tsx b/wagtail_localize/static_src/legacy/main.tsx deleted file mode 100644 index 2cbf503c..00000000 --- a/wagtail_localize/static_src/legacy/main.tsx +++ /dev/null @@ -1 +0,0 @@ -import './editor/main'; diff --git a/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html b/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html index 9afc3b6f..e41adb9b 100644 --- a/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html +++ b/wagtail_localize/templates/wagtail_localize/admin/edit_translation.html @@ -6,19 +6,17 @@ {% block titletag %}{% blocktrans with instance=translation.source.as_instance locale=translation.target_locale %}Translation of {{ instance }} into {{ locale }}{% endblocktrans %}{% endblock %} {% block content %} - {% if not has_legacy_styling %} - {% if is_page %} -
    - {% include 'wagtailadmin/shared/headers/page_edit_header.html' with page=instance page_for_status=instance page_perms=page_perms content_type=instance.content_type %} - {% include "wagtailadmin/shared/side_panels.html" with page=instance page_for_status=instance page_perms=page_perms content_type=instance.content_type in_explorer=True %} -
    - {% else %} -
    - {% include 'wagtail_localize/admin/includes/generic_header.html' %} - {# FIXME: include side panels #} -
    - {% include "wagtailadmin/shared/header.html" with title=instance icon="snippet" merged=1 only %} - {% endif %} + {% if is_page %} +
    + {% include 'wagtailadmin/shared/headers/page_edit_header.html' with page=instance page_for_status=instance page_perms=page_perms content_type=instance.content_type %} + {% include "wagtailadmin/shared/side_panels.html" with page=instance page_for_status=instance page_perms=page_perms content_type=instance.content_type in_explorer=True %} +
    + {% else %} +
    + {% include 'wagtail_localize/admin/includes/generic_header.html' %} + {# FIXME: include side panels #} +
    + {% include "wagtailadmin/shared/header.html" with title=instance icon="snippet" merged=1 only %} {% endif %}
    {# Generates the CSRF token hidden input. This is read by the JavaScript. #} @@ -26,31 +24,17 @@
    {% endblock %} -{% block extra_css %} - {% if has_legacy_styling %} - {% include "wagtailadmin/pages/_editor_css.html" %} - {% endif %} -{% endblock %} - {% block extra_js %} {% include "wagtailadmin/pages/_editor_js.html" %} - - {% if has_legacy_styling %} - - - - - {% else %} - - - - - - - - - {% endif %} + + + + + + + + {% endblock %} diff --git a/wagtail_localize/test/models.py b/wagtail_localize/test/models.py index 5936d912..fa198287 100644 --- a/wagtail_localize/test/models.py +++ b/wagtail_localize/test/models.py @@ -234,9 +234,6 @@ def get_translatable_segments(self, value): return [StringSegmentValue("foo", "{} and some extra".format(value))] -SF_KWARGS = {"use_json_field": True} - - class TestPage(Page): test_charfield = models.CharField( gettext_lazy("char field"), max_length=255, blank=True, null=True, default="" @@ -248,7 +245,7 @@ class TestPage(Page): test_richtextfield = RichTextField(blank=True) test_null_richtextfield = RichTextField(blank=True, null=True) - test_streamfield = StreamField(TestStreamBlock, blank=True, **SF_KWARGS) + test_streamfield = StreamField(TestStreamBlock, blank=True, use_json_field=True) test_snippet = models.ForeignKey( TestSnippet, null=True, blank=True, on_delete=models.SET_NULL @@ -265,7 +262,7 @@ class TestPage(Page): test_synchronized_richtextfield = RichTextField(blank=True) test_synchronized_streamfield = StreamField( - TestStreamBlock, blank=True, **SF_KWARGS + TestStreamBlock, blank=True, use_json_field=True ) test_synchronized_image = models.ForeignKey( @@ -451,7 +448,7 @@ class TestGenerateTranslatableFieldsPage(Page): test_urlfield = models.URLField(blank=True) test_richtextfield = RichTextField(blank=True) - test_streamfield = StreamField(TestStreamBlock, blank=True, **SF_KWARGS) + test_streamfield = StreamField(TestStreamBlock, blank=True, use_json_field=True) test_snippet = models.ForeignKey( TestSnippet, null=True, blank=True, on_delete=models.SET_NULL diff --git a/wagtail_localize/tests/test_edit_translation.py b/wagtail_localize/tests/test_edit_translation.py index 9ce9365b..b5bc9e57 100644 --- a/wagtail_localize/tests/test_edit_translation.py +++ b/wagtail_localize/tests/test_edit_translation.py @@ -4,6 +4,7 @@ import polib +from django.contrib.admin.utils import quote from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType @@ -29,7 +30,6 @@ from wagtail.models import Locale, Page from wagtail.test.utils import WagtailTestUtils -from wagtail_localize.compat import get_snippet_delete_url, get_snippet_edit_url from wagtail_localize.models import ( OverridableSegment, SegmentOverride, @@ -57,7 +57,7 @@ edit_string_translation, ) -from .utils import assert_permission_denied, get_snippet_add_url_from_args +from .utils import assert_permission_denied RICH_TEXT_DATA = '

    This is a heading

    This is a paragraph. <foo> Bold text

    ' @@ -566,7 +566,12 @@ def test_page_chooser_in_orderable(self): ) TranslationSource.update_or_create_from_instance(self.snippet) - response = self.client.get(get_snippet_edit_url(self.fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed( response, "wagtail_localize/admin/edit_translation.html" @@ -1561,7 +1566,12 @@ def test_edit_page_from_outdated_translation_source(self): ) def test_edit_snippet_translation(self): - response = self.client.get(get_snippet_edit_url(self.fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed( response, "wagtail_localize/admin/edit_translation.html" @@ -1593,7 +1603,10 @@ def test_edit_snippet_translation(self): { "title": f"TestSnippet object ({self.snippet.id})", "locale": {"code": "en", "displayName": "English"}, - "editUrl": get_snippet_edit_url(self.snippet), + "editUrl": reverse( + f"wagtailsnippets_{self.snippet._meta.app_label}_{self.snippet._meta.model_name}:edit", + args=[quote(self.snippet.pk)], + ), } ], ) @@ -1609,7 +1622,10 @@ def test_edit_snippet_translation(self): self.assertIsNone(props["links"]["unlockUrl"]) self.assertEqual( props["links"]["deleteUrl"], - get_snippet_delete_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:delete", + args=[quote(self.fr_snippet.pk)], + ), ) self.assertEqual(props["previewModes"], []) @@ -1645,7 +1661,12 @@ def test_cant_edit_snippet_translation_without_perms(self): self.moderators_group.permissions.filter( content_type=ContentType.objects.get_for_model(TestSnippet) ).delete() - response = self.client.get(get_snippet_edit_url(self.fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + ) assert_permission_denied(self, response) @@ -1678,7 +1699,12 @@ def test_edit_nested_snippet_translation(self): snippet_translation.save_target() fr_snippet = snippet.get_translation(self.fr_locale) - response = self.client.get(get_snippet_edit_url(fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{fr_snippet._meta.app_label}_{fr_snippet._meta.model_name}:edit", + args=[quote(fr_snippet.pk)], + ) + ) self.assertEqual(response.status_code, 200) def test_edit_translation_when_block_deleted_from_source_page(self): @@ -1981,7 +2007,10 @@ def test_publish_snippet_translation(self): ) response = self.client.post( - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), { "action": "publish", }, @@ -1989,7 +2018,10 @@ def test_publish_snippet_translation(self): self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) # Check success message @@ -2017,7 +2049,10 @@ def test_cant_publish_snippet_translation_without_perms(self): ).delete() response = self.client.post( - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), { "action": "publish", }, @@ -2123,7 +2158,10 @@ def test_restart_snippet_translation(self): self.snippet_translation.enabled = False self.snippet_translation.save() response = self.client.post( - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), { "localize-restart-translation": "yes", }, @@ -2131,7 +2169,10 @@ def test_restart_snippet_translation(self): self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) self.snippet_translation.refresh_from_db() @@ -2168,28 +2209,43 @@ def test_snippet(self): self.snippet_translation.enabled = False self.snippet_translation.save() - response = self.client.get(get_snippet_edit_url(self.fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + ) self.assertContains(response, "Start Synced translation") def test_doesnt_show_when_no_translation_for_snippet(self): self.snippet_translation.delete() - response = self.client.get(get_snippet_edit_url(self.fr_snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + ) self.assertNotContains(response, "Start Synced translation") def test_doesnt_show_on_create_for_snippet(self): response = self.client.get( - get_snippet_add_url_from_args( - TestSnippet._meta.app_label, TestSnippet._meta.model_name + reverse( + f"wagtailsnippets_{TestSnippet._meta.app_label}_{TestSnippet._meta.model_name}:add" ) ) self.assertNotContains(response, "Start Synced translation") def test_doesnt_show_for_untranslatable_snippet(self): snippet = NonTranslatableSnippet.objects.create(field="Test") - response = self.client.get(get_snippet_edit_url(snippet)) + response = self.client.get( + reverse( + f"wagtailsnippets_{snippet._meta.app_label}_{snippet._meta.model_name}:edit", + args=[quote(snippet.pk)], + ) + ) self.assertNotContains(response, "Start Synced translation") @@ -2916,13 +2972,19 @@ def test_upload_pofile_snippet(self): str(po).encode("utf-8"), content_type="text/x-gettext-translation", ), - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) translation = StringTranslation.objects.get( @@ -3074,13 +3136,19 @@ def test_upload_pofile_snippet_invalid_file(self): "Foo".encode("utf-8"), content_type="text/x-gettext-translation", ), - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) # User should be warned with a message @@ -3132,13 +3200,19 @@ def test_upload_pofile_snippet_filename_instead_of_file(self): f.name.encode("utf-8"), content_type="text/x-gettext-translation", ), - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) # User should be warned with a message @@ -3178,13 +3252,19 @@ def test_upload_pofile_snippet_against_wrong_translationid(self): str(po).encode("utf-8"), content_type="text/x-gettext-translation", ), - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) # User should be warned with a message @@ -3246,7 +3326,10 @@ def test_cant_upload_pofile_without_snippet_perms(self): str(po).encode("utf-8"), content_type="text/x-gettext-translation", ), - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) @@ -3313,13 +3396,19 @@ def test_machine_translate_snippet(self): "wagtail_localize:machine_translate", args=[self.snippet_translation.id] ), { - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) translation = StringTranslation.objects.get( @@ -3420,12 +3509,20 @@ def test_machine_translate_snippet_when_already_translated(self): reverse( "wagtail_localize:machine_translate", args=[self.snippet_translation.id] ), - {"next": get_snippet_edit_url(self.fr_snippet)}, + { + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ) + }, ) self.assertRedirects( response, - get_snippet_edit_url(self.fr_snippet), + reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), ) # User should be warned with a message @@ -3473,7 +3570,10 @@ def test_cant_machine_translate_without_snippet_perms(self): "wagtail_localize:machine_translate", args=[self.snippet_translation.id] ), { - "next": get_snippet_edit_url(self.fr_snippet), + "next": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), }, ) diff --git a/wagtail_localize/tests/test_submit_translations.py b/wagtail_localize/tests/test_submit_translations.py index 816d8168..d83b24ec 100644 --- a/wagtail_localize/tests/test_submit_translations.py +++ b/wagtail_localize/tests/test_submit_translations.py @@ -1,3 +1,4 @@ +from django.contrib.admin.utils import quote from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType @@ -6,7 +7,6 @@ from wagtail.models import Locale, Page, PageViewRestriction from wagtail.test.utils import WagtailTestUtils -from wagtail_localize.compat import get_snippet_edit_url from wagtail_localize.models import Translation, TranslationSource from wagtail_localize.test.models import ( NonTranslatableSnippet, @@ -16,11 +16,7 @@ TestWithTranslationModeEnabledPage, ) -from .utils import ( - assert_permission_denied, - get_snippet_list_url_from_args, - make_test_page, -) +from .utils import assert_permission_denied, make_test_page def strip_user_perms(): @@ -642,7 +638,7 @@ def setUp(self): def test(self): response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertContains( @@ -657,7 +653,7 @@ def test_hides_if_snippet_already_translated(self): de_snippet.save() response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertNotContains(response, "Translate") @@ -666,9 +662,7 @@ def test_hides_if_snippet_isnt_translatable(self): self.en_snippet.copy_for_translation(self.de_locale) response = self.client.get( - get_snippet_list_url_from_args( - "wagtail_localize_test", "nontranslatablesnippet" - ) + reverse("wagtailsnippets_wagtail_localize_test_nontranslatablesnippet:list") ) self.assertNotContains(response, "Translate") @@ -677,7 +671,7 @@ def test_hides_if_user_doesnt_have_permission(self): strip_user_perms() response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertNotContains(response, "Translate") @@ -825,7 +819,10 @@ def test_post_submit_snippet_translation(self): self.assertRedirects( response, - get_snippet_edit_url(translated_snippet), + reverse( + f"wagtailsnippets_{translated_snippet._meta.app_label}_{translated_snippet._meta.model_name}:edit", + args=[quote(translated_snippet.pk)], + ), ) def test_post_submit_snippet_translation_into_multiple_locales(self): @@ -839,7 +836,10 @@ def test_post_submit_snippet_translation_into_multiple_locales(self): self.assertRedirects( response, - get_snippet_edit_url(self.en_snippet), + reverse( + f"wagtailsnippets_{self.en_snippet._meta.app_label}_{self.en_snippet._meta.model_name}:edit", + args=[quote(self.en_snippet.pk)], + ), ) # Check French translation diff --git a/wagtail_localize/tests/test_update_translations.py b/wagtail_localize/tests/test_update_translations.py index 91fd013b..0f22bb05 100644 --- a/wagtail_localize/tests/test_update_translations.py +++ b/wagtail_localize/tests/test_update_translations.py @@ -1,5 +1,6 @@ from unittest import mock +from django.contrib.admin.utils import quote from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, Permission from django.contrib.contenttypes.models import ContentType @@ -9,15 +10,10 @@ from wagtail.models import Locale, Page, PageViewRestriction from wagtail.test.utils import WagtailTestUtils -from wagtail_localize.compat import get_snippet_edit_url from wagtail_localize.models import StringSegment, Translation, TranslationSource from wagtail_localize.test.models import NonTranslatableSnippet, TestSnippet -from .utils import ( - assert_permission_denied, - get_snippet_list_url_from_args, - make_test_page, -) +from .utils import assert_permission_denied, make_test_page def strip_user_perms(): @@ -146,7 +142,7 @@ def setUp(self): def test(self): response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertContains( @@ -160,7 +156,7 @@ def test_hides_if_snippet_hasnt_got_translations(self): self.source.delete() response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertNotContains(response, "Sync translated snippets") @@ -169,7 +165,7 @@ def test_hides_if_user_doesnt_have_permission(self): strip_user_perms() response = self.client.get( - get_snippet_list_url_from_args("wagtail_localize_test", "testsnippet") + reverse("wagtailsnippets_wagtail_localize_test_testsnippet:list") ) self.assertNotContains(response, "Sync translated snippets") @@ -271,7 +267,10 @@ def test_get_update_snippet_translation(self): { "title": str(self.fr_snippet), "locale": self.fr_locale, - "edit_url": get_snippet_edit_url(self.fr_snippet), + "edit_url": reverse( + f"wagtailsnippets_{self.fr_snippet._meta.app_label}_{self.fr_snippet._meta.model_name}:edit", + args=[quote(self.fr_snippet.pk)], + ), } ], ) @@ -381,7 +380,13 @@ def test_post_update_snippet_translation(self): ) ) - self.assertRedirects(response, get_snippet_edit_url(self.en_snippet)) + self.assertRedirects( + response, + reverse( + f"wagtailsnippets_{self.en_snippet._meta.app_label}_{self.en_snippet._meta.model_name}:edit", + args=[quote(self.en_snippet.pk)], + ), + ) # The FR version shouldn't be updated yet self.fr_snippet.refresh_from_db() @@ -401,7 +406,10 @@ def test_post_update_snippet_translation_with_publish_translations(self): self.assertRedirects( response, - get_snippet_edit_url(self.en_snippet), + reverse( + f"wagtailsnippets_{self.en_snippet._meta.app_label}_{self.en_snippet._meta.model_name}:edit", + args=[quote(self.en_snippet.pk)], + ), ) # The FR version should be updated diff --git a/wagtail_localize/tests/utils.py b/wagtail_localize/tests/utils.py index fb6fc211..14e49485 100644 --- a/wagtail_localize/tests/utils.py +++ b/wagtail_localize/tests/utils.py @@ -22,11 +22,3 @@ def make_test_page(parent, cls=None, **kwargs): cls = cls or TestPage kwargs.setdefault("title", "Test page") return parent.add_child(instance=cls(**kwargs)) - - -def get_snippet_list_url_from_args(app_label, model_name): - return reverse(f"wagtailsnippets_{app_label}_{model_name}:list") - - -def get_snippet_add_url_from_args(app_label, model_name): - return reverse(f"wagtailsnippets_{app_label}_{model_name}:add") diff --git a/wagtail_localize/views/edit_translation.py b/wagtail_localize/views/edit_translation.py index 2ef8997b..59365b52 100644 --- a/wagtail_localize/views/edit_translation.py +++ b/wagtail_localize/views/edit_translation.py @@ -50,11 +50,7 @@ from wagtail.snippets.permissions import get_permission_name, user_can_edit_snippet_type from wagtail.utils.decorators import xframe_options_sameorigin_override -from wagtail_localize.compat import ( - DATE_FORMAT, - get_snippet_delete_url, - get_snippet_edit_url, -) +from wagtail_localize.compat import DATE_FORMAT from wagtail_localize.machine_translators import get_machine_translator from wagtail_localize.models import ( OverridableSegment, @@ -721,7 +717,10 @@ def get_edit_url(instance): return reverse("wagtailadmin_pages:edit", args=[instance.id]) elif instance._meta.model in get_snippet_models(): - return get_snippet_edit_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return reverse( @@ -736,7 +735,10 @@ def get_delete_url(instance): if isinstance(instance, Page): return reverse("wagtailadmin_pages:delete", args=[instance.id]) elif instance._meta.model in get_snippet_models(): - return get_snippet_delete_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:delete", + args=[quote(instance.pk)], + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return reverse( @@ -893,7 +895,6 @@ def get_translation_progress(segment, locale): else: add_convert_to_alias_url = False - has_legacy_styling = False side_panels = ( LocalizedPageSidePanels(request, instance, translation) if is_page else None ) @@ -911,7 +912,6 @@ def get_translation_progress(segment, locale): # These props are passed directly to the TranslationEditor react component "props": json.dumps( { - "has_legacy_styling": has_legacy_styling, "adminBaseUrl": reverse("wagtailadmin_home"), "object": { "title": str(instance), @@ -1024,7 +1024,6 @@ def get_translation_progress(segment, locale): }, cls=DjangoJSONEncoder, ), - "has_legacy_styling": has_legacy_styling, }, ) @@ -1097,7 +1096,12 @@ def restart_translation(request, translation, instance): if isinstance(instance, Page): return redirect("wagtailadmin_pages:edit", instance.id) elif instance._meta.model in get_snippet_models(): - return redirect(get_snippet_edit_url(instance)) + return redirect( + reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return redirect( "{app_label}_{model_name}_modeladmin_edit".format( diff --git a/wagtail_localize/views/snippets_api.py b/wagtail_localize/views/snippets_api.py index 9c6b3af8..94f63972 100644 --- a/wagtail_localize/views/snippets_api.py +++ b/wagtail_localize/views/snippets_api.py @@ -1,8 +1,8 @@ +from django.contrib.admin.utils import quote +from django.urls import reverse from rest_framework import fields, serializers, viewsets from wagtail.snippets.views.snippets import get_snippet_model_from_url_params -from wagtail_localize.compat import get_snippet_edit_url - class BaseSnippetSerializer(serializers.ModelSerializer): id = fields.ReadOnlyField(source="pk") @@ -13,7 +13,10 @@ def get_title(self, instance): return str(instance) def get_edit_url(self, instance): - return get_snippet_edit_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) class SnippetViewSet(viewsets.ModelViewSet): diff --git a/wagtail_localize/views/submit_translations.py b/wagtail_localize/views/submit_translations.py index 4bb3c258..0390980f 100644 --- a/wagtail_localize/views/submit_translations.py +++ b/wagtail_localize/views/submit_translations.py @@ -1,6 +1,6 @@ from django import forms from django.contrib import messages -from django.contrib.admin.utils import unquote +from django.contrib.admin.utils import quote, unquote from django.core.exceptions import PermissionDenied from django.db import transaction from django.http import Http404 @@ -14,7 +14,6 @@ from wagtail.models import Locale, Page, TranslatableMixin from wagtail.snippets.views.snippets import get_snippet_model_from_url_params -from wagtail_localize.compat import get_snippet_edit_url_from_args from wagtail_localize.components import TranslationComponentManager from wagtail_localize.operations import translate_object, translate_page_subtree from wagtail_localize.tasks import background @@ -221,19 +220,16 @@ def get_object(self): return get_object_or_404(model, pk=unquote(self.kwargs["pk"])) def get_default_success_url(self, translated_snippet=None): + pk = self.kwargs["pk"] + if translated_snippet: # If the editor chose a single locale to translate to, redirect to # the newly translated snippet's edit view. - return get_snippet_edit_url_from_args( - self.kwargs["app_label"], - self.kwargs["model_name"], - translated_snippet.pk, - ) + pk = translated_snippet.pk - return get_snippet_edit_url_from_args( - self.kwargs["app_label"], - self.kwargs["model_name"], - self.kwargs["pk"], + return reverse( + f"wagtailsnippets_{self.kwargs['app_label']}_{self.kwargs['model_name']}:edit", + args=[quote(pk)], ) def get_success_message(self, locales): diff --git a/wagtail_localize/views/update_translations.py b/wagtail_localize/views/update_translations.py index 97c3e800..9d19eb95 100644 --- a/wagtail_localize/views/update_translations.py +++ b/wagtail_localize/views/update_translations.py @@ -15,7 +15,6 @@ from wagtail.snippets.models import get_snippet_models from wagtail.utils.version import get_main_version -from wagtail_localize.compat import get_snippet_edit_url from wagtail_localize.models import TranslationSource from wagtail_localize.views.submit_translations import TranslationComponentManager @@ -66,7 +65,10 @@ def get_default_success_url(self): return reverse("wagtailadmin_explore", args=[instance.get_parent().id]) elif instance._meta.model in get_snippet_models(): - return get_snippet_edit_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return reverse( @@ -81,7 +83,10 @@ def get_edit_url(self, instance): return reverse("wagtailadmin_pages:edit", args=[instance.id]) elif instance._meta.model in get_snippet_models(): - return get_snippet_edit_url(instance) + return reverse( + f"wagtailsnippets_{instance._meta.app_label}_{instance._meta.model_name}:edit", + args=[quote(instance.pk)], + ) elif "wagtail_localize.modeladmin" in settings.INSTALLED_APPS: return reverse( diff --git a/wagtail_localize/wagtail_hooks.py b/wagtail_localize/wagtail_hooks.py index 0150ed06..fb8de887 100644 --- a/wagtail_localize/wagtail_hooks.py +++ b/wagtail_localize/wagtail_hooks.py @@ -133,11 +133,6 @@ def register_submit_translation_permission(): ) -def set_button_icon(button, icon_name): - button.icon_name = icon_name - return button - - def page_listing_more_buttons(page, page_perms, next_url=None): if not page.is_root() and page_perms.user.has_perm( "wagtail_localize.submit_translation" @@ -152,9 +147,11 @@ def page_listing_more_buttons(page, page_perms, next_url=None): if has_locale_to_translate_to: url = reverse("wagtail_localize:submit_page_translation", args=[page.id]) - yield set_button_icon( - wagtailadmin_widgets.Button(_("Translate this page"), url, priority=60), - "wagtail-localize-language", + yield wagtailadmin_widgets.Button( + _("Translate this page"), + url, + priority=60, + icon_name="wagtail-localize-language", ) # If the page is the source for translations, show "Sync translated pages" button @@ -164,11 +161,8 @@ def page_listing_more_buttons(page, page_perms, next_url=None): if next_url is not None: url += "?" + urlencode({"next": next_url}) - yield set_button_icon( - wagtailadmin_widgets.Button( - _("Sync translated pages"), url, priority=65 - ), - "resubmit", + yield wagtailadmin_widgets.Button( + _("Sync translated pages"), url, priority=60, icon_name="resubmit" ) From 0efe060c94152bf7aca31bca8c8402e9f26d53de Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 9 Feb 2023 11:29:55 +0800 Subject: [PATCH 10/13] Fixed tox envlist --- testmanage.py | 2 +- tox.ini | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/testmanage.py b/testmanage.py index a42689d3..757bc015 100644 --- a/testmanage.py +++ b/testmanage.py @@ -56,7 +56,7 @@ def runtests(): try: execute_from_command_line(argv) finally: - from wagtail.tests.settings import MEDIA_ROOT, STATIC_ROOT + from wagtail.test.settings import MEDIA_ROOT, STATIC_ROOT shutil.rmtree(STATIC_ROOT, ignore_errors=True) shutil.rmtree(MEDIA_ROOT, ignore_errors=True) diff --git a/tox.ini b/tox.ini index 9efda7f1..8bb447ab 100644 --- a/tox.ini +++ b/tox.ini @@ -5,9 +5,8 @@ usedevelop = True envlist = python{3.7}-django{3.2}-wagtail{4.1,4.2,main}-{sqlite,postgres12} python{3.8,3.9,3.10,3.11}-django{3.2,4.0,4.1,main}-wagtail{4.1,4.2,main}-sqlite - python{3.8,3.9,3.10}-wagtail{4.1,4.2,main}-{sqlite,postgres12,postgres15} - python{3.8,3.9,3.10}-wagtail{3.2}-postgres12 - python{3.11}-wagtail{4.1,4.2,main}-postgres15 + python{3.8,3.9,3.10}-django{3.2}-wagtail{4.1,4.2,main}-postgres12 + python{3.8,3.9,3.10,3.11}-django{4.0,4.1,main}-wagtail{4.1,4.2,main}-postgres15 [flake8] # E501: Line too long From aa2c0c479495ac1c72a474b68519d3ebef7bc0ab Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Fri, 10 Feb 2023 11:36:06 +0800 Subject: [PATCH 11/13] Update testing --- .github/workflows/test.yml | 136 ++----------------------------------- tox.ini | 31 +++++---- 2 files changed, 23 insertions(+), 144 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 42290615..59a94163 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,125 +30,12 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} - test-sqlite: + test-python: runs-on: ubuntu-latest needs: lint strategy: matrix: - python: ['3.8', '3.9', '3.10', '3.11'] - django: ['3.2', '4.0', '4.1'] - wagtail: ['4.1', '4.2'] - experimental: [false] - include: - - python: '3.7' - django: '3.2' - wagtail: '4.1' - experimental: false - - python: '3.7' - django: '3.2' - wagtail: '4.2' - experimental: false - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - name: Install Tox - run: | - python -m pip install tox - - name: Cache tox environments - id: cache-tox - uses: actions/cache@v3 - with: - path: .tox - key: tox-${{ hashFiles('pyproject.toml') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-sqlite - - name: Test - run: | - tox - env: - TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-sqlite - - test-postgres: - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental }} - needs: lint - strategy: - matrix: - python: ['3.8', '3.9', '3.10'] - django: ['4.0', '4.1'] - wagtail: ['4.1', '4.2'] - postgres: ['15'] - experimental: [false] - include: - - python: '3.7' - django: '3.2' - wagtail: '4.1' - postgres: '12' - experimental: false - - python: '3.7' - django: '3.2' - wagtail: '4.2' - postgres: '12' - experimental: false - - python: '3.8' - django: '3.2' - wagtail: '4.1' - postgres: '12' - experimental: false - - python: '3.8' - django: '3.2' - wagtail: '4.2' - postgres: '12' - experimental: false - - python: '3.9' - django: '3.2' - wagtail: '4.1' - postgres: '12' - experimental: false - - python: '3.9' - django: '3.2' - wagtail: '4.2' - postgres: '12' - experimental: false - - python: '3.10' - django: '3.2' - wagtail: '4.1' - postgres: '12' - experimental: false - - python: '3.10' - django: '3.2' - wagtail: '4.2' - postgres: '12' - experimental: false - - python: '3.11' - django: '4.0' - wagtail: '4.1' - postgres: '15' - experimental: false - - python: '3.11' - django: '4.0' - wagtail: '4.2' - postgres: '15' - experimental: false - - python: '3.11' - django: '4.1' - wagtail: '4.1' - postgres: '15' - experimental: false - - python: '3.11' - django: '4.1' - wagtail: '4.2' - postgres: '15' - experimental: false - services: - postgres: - image: postgres:${{ matrix.postgres }} - env: - POSTGRES_PASSWORD: postgres - ports: - - 5432:5432 - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + python: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v3 @@ -156,21 +43,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - - name: Install Tox - run: | - python -m pip install tox - - name: Cache tox environments - id: cache-tox - uses: actions/cache@v3 - with: - path: .tox - key: tox-${{ hashFiles('pyproject.toml') }}-py${{ matrix.python }}-dj${{ matrix.django }}-w${{ matrix.wagtail }}-postgres${{ matrix.postgres }} - - name: Test + - name: Install dependencies run: | - tox - env: - DATABASE_URL: postgres://postgres:postgres@localhost:5432/wagtail_localize - TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}-postgres${{ matrix.postgres }} + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Test with tox + run: tox coverage: runs-on: ubuntu-latest diff --git a/tox.ini b/tox.ini index 8bb447ab..bd0cc91e 100644 --- a/tox.ini +++ b/tox.ini @@ -3,10 +3,18 @@ skipsdist = True usedevelop = True envlist = - python{3.7}-django{3.2}-wagtail{4.1,4.2,main}-{sqlite,postgres12} - python{3.8,3.9,3.10,3.11}-django{3.2,4.0,4.1,main}-wagtail{4.1,4.2,main}-sqlite - python{3.8,3.9,3.10}-django{3.2}-wagtail{4.1,4.2,main}-postgres12 - python{3.8,3.9,3.10,3.11}-django{4.0,4.1,main}-wagtail{4.1,4.2,main}-postgres15 + python{3.7}-django{3.2}-wagtail{4.1,4.2}-{sqlite,postgres12} + python{3.8,3.9,3.10}-django{3.2}-wagtail{4.1,4.2}-{sqlite,postgres12} + python{3.8,3.9,3.10}-django{4.0,4.1}-wagtail{4.1,4.2}-{sqlite,postgres15} + python{3.11}-django{4.1}-wagtail{4.1,4.2}-{sqlite,postgres15} + +[gh-actions] +python = + 3.7: python3.7 + 3.8: python3.8 + 3.9: python3.9 + 3.10: python3.10 + 3.11: python3.11 [flake8] # E501: Line too long @@ -18,24 +26,17 @@ exclude = migrations,node_modules install_command = pip install -e ".[testing]" -U {opts} {packages} commands = coverage run testmanage.py test --deprecation all {posargs: -v 2} -basepython = - python3.7: python3.7 - python3.8: python3.8 - python3.9: python3.9 - python3.10: python3.10 - python3.11: python3.11 - deps = coverage typing_extensions>=4.0 - django3.2: Django~=3.2 - django4.0: Django~=4.0 - django4.1: Django~=4.1 + django3.2: Django>=3.2,<3.3 + django4.0: Django>=4.0,<4.1 + django4.1: Django>=4.1,<4.2 djangomain: git+https://github.com/django/django.git@main#egg=Django wagtail4.1: wagtail>=4.1,<4.2 - wagtail4.2: wagtail>=4.2rc1,<5.0 + wagtail4.2: wagtail>=4.2,<5.0 wagtailmain: git+https://github.com/wagtail/wagtail.git # Pinned to work around UTC connection error From 437beb39676dafad2fe82cc759cf74770a5307c6 Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Tue, 14 Feb 2023 13:20:00 +0000 Subject: [PATCH 12/13] Make sure postgres tests are actually using postgres --- .github/workflows/test.yml | 48 +++++++++++++++++++++++++++++++++++++- tox.ini | 9 +++---- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59a94163..d59a1150 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} - test-python: + test-sqlite: runs-on: ubuntu-latest needs: lint strategy: @@ -50,6 +50,52 @@ jobs: - name: Test with tox run: tox + test-postgres: + runs-on: ubuntu-latest + needs: lint + strategy: + matrix: + python: ["3.7", "3.8", "3.9", "3.10", "3.11"] + database: ["postgres"] + + services: + postgres: + image: postgres + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install dependencies + id: install-dependencies + run: | + python -m pip install --upgrade pip + python -m pip install tox tox-gh-actions + - name: Test with tox + id: test-with-tox + run: | + tox + env: + DB_NAME: postgres + DB_USER: postgres + DB_PASSWORD: postgres + DB_HOST: localhost + DB_PORT: 5432 + DATABASE: ${{ matrix.database }} + coverage: runs-on: ubuntu-latest needs: lint diff --git a/tox.ini b/tox.ini index bd0cc91e..6775bfd3 100644 --- a/tox.ini +++ b/tox.ini @@ -16,6 +16,10 @@ python = 3.10: python3.10 3.11: python3.11 +[gh-actions:env] +DATABASE = + postgres: postgres + [flake8] # E501: Line too long # W503: line break before binary operator (superseded by W504 line break after binary operator) @@ -41,10 +45,7 @@ deps = # Pinned to work around UTC connection error # https://stackoverflow.com/questions/68024060/assertionerror-database-connection-isnt-set-to-utc - postgres12: psycopg2==2.8.6 - - # https://www.psycopg.org/docs/index.html - postgres15: psycopg2==2.9.5 + postgres: psycopg2 setenv = postgres: DATABASE_URL={env:DATABASE_URL:postgres:///wagtail_localize} From 8ff740282044369fce90b0f9211fed4a84e73f22 Mon Sep 17 00:00:00 2001 From: Nick Moreton Date: Tue, 14 Feb 2023 13:24:22 +0000 Subject: [PATCH 13/13] Add WAGTAILADMIN_BASE_URL to test settings --- wagtail_localize/test/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wagtail_localize/test/settings.py b/wagtail_localize/test/settings.py index 60c83001..e5c95c61 100644 --- a/wagtail_localize/test/settings.py +++ b/wagtail_localize/test/settings.py @@ -188,3 +188,5 @@ "BACKEND": "wagtail.search.backends.database", } } + +WAGTAILADMIN_BASE_URL = "http://example.com"