From 180ec8164fbf6743fa3cd28429b7141915499fee Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 11:35:26 +0800 Subject: [PATCH 01/10] Start of Wagtail 5.0 support - Update documentation and tests --- .github/workflows/main.yml | 23 ++++++++++++----------- CHANGELOG.md | 7 +++++++ README.md | 2 +- docs/1_getting_started.md | 4 ++-- docs/2_adding_to_a_page.md | 8 ++++---- docs/3_adding_to_a_streamfield.md | 8 ++++---- docs/4_reference.md | 14 +++++++------- setup.py | 8 +++----- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4ee0f0..87da4c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,22 +8,23 @@ jobs: strategy: matrix: python-version: - - "3.7" - "3.8" - "3.9" - "3.10" - "3.11" wagtail-version: - - "2.15.6" - - "4.1.2" + - "4.1" - "4.2" + - "5.0" exclude: - python-version: "3.11" - wagtail-version: "2.15.6" + wagtail-version: "4.1" + - python-version: "3.11" + wagtail-version: "4.2" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -39,7 +40,7 @@ jobs: runs-on: ubuntu-latest needs: test steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: psf/black@stable with: options: "--check --verbose" @@ -50,8 +51,8 @@ jobs: runs-on: ubuntu-latest needs: test steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: 3.8 - name: Install dependencies @@ -64,8 +65,8 @@ jobs: runs-on: ubuntu-latest needs: [test, lint-black, lint-isort] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: 3.8 - name: Install dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 25d923c..bb998f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Add Wagtail 5.0 support (@katdom13) +- Add Python 4.2 support (@katdom13) +- Add Python 3.11 support + ### Changed ### Fixed ### Removed +- Drop Wagtail < 4.1 support (@katdom13) +- Drop Django 4.0 support (@katdom13) +- Drop Python 3.7 support (@katdom13) ## [1.4.1] - 2023-02-19 ### Added diff --git a/README.md b/README.md index ecda08a..87db983 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Introduces panels for selecting colors in Wagtail. ## Example ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_color_panel.fields import ColorField from wagtail_color_panel.edit_handlers import NativeColorPanel diff --git a/docs/1_getting_started.md b/docs/1_getting_started.md index e744146..441c7fa 100644 --- a/docs/1_getting_started.md +++ b/docs/1_getting_started.md @@ -2,8 +2,8 @@ ### Requirements -- Python 3.7+ -- Wagtail 2.15+ and Django +- Python 3.8+ +- Wagtail 4.1+ and Django 3.2+ - [A browser that supports `input type="color"`](https://caniuse.com/#feat=input-color) diff --git a/docs/2_adding_to_a_page.md b/docs/2_adding_to_a_page.md index 1ed63f4..5bf5b64 100644 --- a/docs/2_adding_to_a_page.md +++ b/docs/2_adding_to_a_page.md @@ -3,7 +3,7 @@ ### First create a page ```python -from wagtail.core.models import Page +from wagtail.models import Page class MyPage(Page): ... @@ -15,7 +15,7 @@ class MyPage(Page): Define a ColorField that represents your color, in this example we call it `color`. ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_color_panel.fields import ColorField class MyPage(Page): @@ -28,7 +28,7 @@ Note: ColorField is built on top of CharField, so its also possible to use `Char ### Add a content panel to represent the field in the admin ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_color_panel.edit_handlers import NativeColorPanel @@ -46,7 +46,7 @@ We're done! After migration a color picker should appear. ### Full example ```python -from wagtail.core.models import Page +from wagtail.models import Page from wagtail_color_panel.fields import ColorField from wagtail_color_panel.edit_handlers import NativeColorPanel diff --git a/docs/3_adding_to_a_streamfield.md b/docs/3_adding_to_a_streamfield.md index e93ff28..50efd7c 100644 --- a/docs/3_adding_to_a_streamfield.md +++ b/docs/3_adding_to_a_streamfield.md @@ -3,17 +3,17 @@ To add the color chooser to a StreamField, import and use the `NativeColorBlock`. ```python -from wagtail.core.models import Page -from wagtail.core.fields import StreamField +from wagtail.models import Page +from wagtail.fields import StreamField from wagtail_color_panel.blocks import NativeColorBlock class MyStreamFieldPage(Page): body = StreamField([ ('color', NativeColorBlock(default="#000000")), - ]) + ], use_json_field=True) content_panels = Page.content_panels + [ - StreamFieldPanel('body'), + FieldPanel('body'), ] ``` diff --git a/docs/4_reference.md b/docs/4_reference.md index 767d80a..13bde1a 100644 --- a/docs/4_reference.md +++ b/docs/4_reference.md @@ -9,7 +9,7 @@ This panel uses the native `=2.15"] +install_requires = ["wagtail>=4.1"] tests_require = ["pytest-django", "wagtail-factories", "pytest"] @@ -40,15 +40,13 @@ "Environment :: Web Environment", "Framework :: Django", "Framework :: Wagtail", - "Framework :: Wagtail :: 2", - "Framework :: Wagtail :: 3", "Framework :: Wagtail :: 4", + "Framework :: Wagtail :: 5", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -56,5 +54,5 @@ "Topic :: Utilities", ], setup_requires=["setuptools_scm", "pytest-runner"], - python_requires=">=3.7", + python_requires=">=3.8", ) From 13463f6916501ff65c40ee08c4292ae9f6f9a14d Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 11:40:12 +0800 Subject: [PATCH 02/10] Ran updatemodulepaths --- tests/settings.py | 2 +- tests/test_block.py | 2 +- tests/test_field.py | 2 +- tests/test_widget.py | 2 +- tests/testapp/migrations/0001_initial.py | 2 +- .../migrations/0002_alter_pagewithstreamfield_body.py | 2 +- tests/testapp/models.py | 6 +++--- tests/urls.py | 2 +- wagtail_color_panel/blocks.py | 2 +- wagtail_color_panel/edit_handlers.py | 2 +- wagtail_color_panel/widgets.py | 4 ++-- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/settings.py b/tests/settings.py index d4aac22..c1fde64 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -26,7 +26,7 @@ "wagtail.images", "wagtail.search", "wagtail.admin", - "wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core", + "wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail", "modelcluster", "taggit", "django.contrib.admin", diff --git a/tests/test_block.py b/tests/test_block.py index 286e78c..55b71c0 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -8,7 +8,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail.test.utils import WagtailTestUtils else: - from wagtail.tests.utils import WagtailTestUtils + from wagtail.test.utils import WagtailTestUtils class BlockTest(TestCase, WagtailTestUtils): diff --git a/tests/test_field.py b/tests/test_field.py index 0063c7c..3976e74 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -10,7 +10,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail.test.utils import WagtailTestUtils else: - from wagtail.tests.utils import WagtailTestUtils + from wagtail.test.utils import WagtailTestUtils class FieldTest(TestCase, WagtailTestUtils): diff --git a/tests/test_widget.py b/tests/test_widget.py index edd962c..b39b74d 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -8,7 +8,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail.test.utils import WagtailTestUtils else: - from wagtail.tests.utils import WagtailTestUtils + from wagtail.test.utils import WagtailTestUtils # from wagtail.admin.panels import get_form_for_model # from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm diff --git a/tests/testapp/migrations/0001_initial.py b/tests/testapp/migrations/0001_initial.py index 22740fe..489c36c 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/tests/testapp/migrations/0001_initial.py @@ -8,7 +8,7 @@ if WAGTAIL_VERSION >= (3, 0): import wagtail.fields as wagtail_fields else: - import wagtail.core.fields as wagtail_fields + import wagtail.fields as wagtail_fields class Migration(migrations.Migration): diff --git a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py index df12607..42cf14a 100644 --- a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py +++ b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py @@ -5,7 +5,7 @@ if WAGTAIL_VERSION >= (3, 0): import wagtail.fields as wagtail_fields else: - import wagtail.core.fields as wagtail_fields + import wagtail.fields as wagtail_fields import wagtail_color_panel.blocks diff --git a/tests/testapp/models.py b/tests/testapp/models.py index fcb3f47..ed6d0db 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -11,9 +11,9 @@ from wagtail.fields import StreamField from wagtail.models import Page else: - from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel - from wagtail.core.fields import StreamField - from wagtail.core.models import Page + from wagtail.admin.panels import FieldPanel, StreamFieldPanel + from wagtail.fields import StreamField + from wagtail.models import Page class PageWithColorField(Page): diff --git a/tests/urls.py b/tests/urls.py index cdeb01e..57f8437 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -5,7 +5,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail import urls as wagtail_urls else: - from wagtail.core import urls as wagtail_urls + from wagtail import urls as wagtail_urls urlpatterns = [ path("admin/", include(wagtailadmin_urls)), diff --git a/wagtail_color_panel/blocks.py b/wagtail_color_panel/blocks.py index b06b544..3f8bd67 100644 --- a/wagtail_color_panel/blocks.py +++ b/wagtail_color_panel/blocks.py @@ -8,7 +8,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail.blocks import FieldBlock else: - from wagtail.core.blocks import FieldBlock + from wagtail.blocks import FieldBlock class NativeColorBlock(FieldBlock): diff --git a/wagtail_color_panel/edit_handlers.py b/wagtail_color_panel/edit_handlers.py index be7fb61..de3f51c 100644 --- a/wagtail_color_panel/edit_handlers.py +++ b/wagtail_color_panel/edit_handlers.py @@ -5,7 +5,7 @@ if WAGTAIL_VERSION >= (3, 0): from wagtail.admin.panels import FieldPanel else: - from wagtail.admin.edit_handlers import FieldPanel + from wagtail.admin.panels import FieldPanel class NativeColorPanel(FieldPanel): diff --git a/wagtail_color_panel/widgets.py b/wagtail_color_panel/widgets.py index 06e9bb4..ba6746d 100644 --- a/wagtail_color_panel/widgets.py +++ b/wagtail_color_panel/widgets.py @@ -9,8 +9,8 @@ from wagtail.telepath import register from wagtail.widget_adapters import WidgetAdapter else: - from wagtail.core.telepath import register - from wagtail.core.widget_adapters import WidgetAdapter + from wagtail.telepath import register + from wagtail.widget_adapters import WidgetAdapter class PolyfillColorInputWidget(widgets.TextInput): From e6a75c2ad3df29371a0ad8b2fcd3fbe125b0293e Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 11:47:40 +0800 Subject: [PATCH 03/10] Cleanup wagtail version conditionals --- tests/settings.py | 4 +--- tests/test_block.py | 6 +----- tests/test_field.py | 6 +----- tests/test_widget.py | 6 +----- tests/testapp/migrations/0001_initial.py | 6 +----- .../0002_alter_pagewithstreamfield_body.py | 10 +--------- tests/testapp/models.py | 20 ++++--------------- tests/urls.py | 6 +----- wagtail_color_panel/blocks.py | 6 +----- wagtail_color_panel/edit_handlers.py | 7 +------ wagtail_color_panel/widgets.py | 9 ++------- 11 files changed, 15 insertions(+), 71 deletions(-) diff --git a/tests/settings.py b/tests/settings.py index c1fde64..a7b2b39 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,7 +1,5 @@ import os -from wagtail import VERSION as WAGTAIL_VERSION - BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ADMINS = (("test@example.com", "test"),) @@ -26,7 +24,7 @@ "wagtail.images", "wagtail.search", "wagtail.admin", - "wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail", + "wagtail", "modelcluster", "taggit", "django.contrib.admin", diff --git a/tests/test_block.py b/tests/test_block.py index 55b71c0..6f66bfd 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -1,14 +1,10 @@ from django.core.exceptions import ValidationError from django.test import TestCase -from wagtail import VERSION as WAGTAIL_VERSION from wagtail_color_panel.blocks import NativeColorBlock from wagtail_color_panel.widgets import ColorInputWidget -if WAGTAIL_VERSION >= (3, 0): - from wagtail.test.utils import WagtailTestUtils -else: - from wagtail.test.utils import WagtailTestUtils +from wagtail.test.utils import WagtailTestUtils class BlockTest(TestCase, WagtailTestUtils): diff --git a/tests/test_field.py b/tests/test_field.py index 3976e74..4ef63a2 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -1,16 +1,12 @@ from django.core.exceptions import ValidationError from django.test import TestCase -from wagtail import VERSION as WAGTAIL_VERSION from tests.testapp.factories import ( PageWithColorFieldPageFactory, PageWithDefaultValuePageFactory, ) -if WAGTAIL_VERSION >= (3, 0): - from wagtail.test.utils import WagtailTestUtils -else: - from wagtail.test.utils import WagtailTestUtils +from wagtail.test.utils import WagtailTestUtils class FieldTest(TestCase, WagtailTestUtils): diff --git a/tests/test_widget.py b/tests/test_widget.py index b39b74d..6b19669 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -1,14 +1,10 @@ from django.test import TestCase -from wagtail import VERSION as WAGTAIL_VERSION from tests.testapp.factories import PageWithColorFieldPageFactory from wagtail_color_panel.edit_handlers import NativeColorPanel from wagtail_color_panel.widgets import ColorInputWidget -if WAGTAIL_VERSION >= (3, 0): - from wagtail.test.utils import WagtailTestUtils -else: - from wagtail.test.utils import WagtailTestUtils +from wagtail.test.utils import WagtailTestUtils # from wagtail.admin.panels import get_form_for_model # from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm diff --git a/tests/testapp/migrations/0001_initial.py b/tests/testapp/migrations/0001_initial.py index 489c36c..1596697 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/tests/testapp/migrations/0001_initial.py @@ -1,14 +1,10 @@ # Generated by Django 3.0.7 on 2020-07-31 06:52 -from wagtail import VERSION as WAGTAIL_VERSION from django.db import migrations, models import django.db.models.deletion import wagtail_color_panel.blocks import wagtail_color_panel.fields -if WAGTAIL_VERSION >= (3, 0): - import wagtail.fields as wagtail_fields -else: - import wagtail.fields as wagtail_fields +import wagtail.fields as wagtail_fields class Migration(migrations.Migration): diff --git a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py index 42cf14a..35644fb 100644 --- a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py +++ b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py @@ -1,11 +1,7 @@ # Generated by Django 3.2.13 on 2022-06-23 02:07 -from wagtail import VERSION as WAGTAIL_VERSION from django.db import migrations -if WAGTAIL_VERSION >= (3, 0): - import wagtail.fields as wagtail_fields -else: - import wagtail.fields as wagtail_fields +import wagtail.fields as wagtail_fields import wagtail_color_panel.blocks @@ -23,9 +19,5 @@ class Migration(migrations.Migration): [("color", wagtail_color_panel.blocks.NativeColorBlock())], use_json_field=True, ) - if WAGTAIL_VERSION >= (3, 0) - else wagtail_fields.StreamField( - [("color", wagtail_color_panel.blocks.NativeColorBlock())] - ), ), ] diff --git a/tests/testapp/models.py b/tests/testapp/models.py index ed6d0db..ce323e5 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -1,19 +1,13 @@ from django.db import models -from wagtail import VERSION as WAGTAIL_VERSION from wagtail_color_panel.blocks import NativeColorBlock from wagtail_color_panel.edit_handlers import NativeColorPanel from wagtail_color_panel.fields import ColorField -if WAGTAIL_VERSION >= (3, 0): - from wagtail.admin.panels import FieldPanel - from wagtail.admin.panels import FieldPanel as StreamFieldPanel - from wagtail.fields import StreamField - from wagtail.models import Page -else: - from wagtail.admin.panels import FieldPanel, StreamFieldPanel - from wagtail.fields import StreamField - from wagtail.models import Page +from wagtail.admin.panels import FieldPanel +from wagtail.admin.panels import FieldPanel as StreamFieldPanel +from wagtail.fields import StreamField +from wagtail.models import Page class PageWithColorField(Page): @@ -48,12 +42,6 @@ class PageWithStreamfield(Page): ], use_json_field=True, ) - if WAGTAIL_VERSION >= (3, 0) - else StreamField( - [ - ("color", NativeColorBlock()), - ] - ) ) content_panels = Page.content_panels + [ diff --git a/tests/urls.py b/tests/urls.py index 57f8437..94196bb 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,11 +1,7 @@ from django.urls import include, path -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.admin import urls as wagtailadmin_urls -if WAGTAIL_VERSION >= (3, 0): - from wagtail import urls as wagtail_urls -else: - from wagtail import urls as wagtail_urls +from wagtail import urls as wagtail_urls urlpatterns = [ path("admin/", include(wagtailadmin_urls)), diff --git a/wagtail_color_panel/blocks.py b/wagtail_color_panel/blocks.py index 3f8bd67..641a917 100644 --- a/wagtail_color_panel/blocks.py +++ b/wagtail_color_panel/blocks.py @@ -1,14 +1,10 @@ from django import forms from django.utils.functional import cached_property -from wagtail import VERSION as WAGTAIL_VERSION from wagtail_color_panel.validators import hex_triplet_validator from wagtail_color_panel.widgets import ColorInputWidget -if WAGTAIL_VERSION >= (3, 0): - from wagtail.blocks import FieldBlock -else: - from wagtail.blocks import FieldBlock +from wagtail.blocks import FieldBlock class NativeColorBlock(FieldBlock): diff --git a/wagtail_color_panel/edit_handlers.py b/wagtail_color_panel/edit_handlers.py index de3f51c..654ee17 100644 --- a/wagtail_color_panel/edit_handlers.py +++ b/wagtail_color_panel/edit_handlers.py @@ -1,11 +1,6 @@ -from wagtail import VERSION as WAGTAIL_VERSION - from wagtail_color_panel.widgets import ColorInputWidget, PolyfillColorInputWidget -if WAGTAIL_VERSION >= (3, 0): - from wagtail.admin.panels import FieldPanel -else: - from wagtail.admin.panels import FieldPanel +from wagtail.admin.panels import FieldPanel class NativeColorPanel(FieldPanel): diff --git a/wagtail_color_panel/widgets.py b/wagtail_color_panel/widgets.py index ba6746d..abfd1c0 100644 --- a/wagtail_color_panel/widgets.py +++ b/wagtail_color_panel/widgets.py @@ -2,15 +2,10 @@ from django.forms import widgets from django.utils.safestring import mark_safe -from wagtail import VERSION as WAGTAIL_VERSION from wagtail.utils.widgets import WidgetWithScript -if WAGTAIL_VERSION >= (3, 0): - from wagtail.telepath import register - from wagtail.widget_adapters import WidgetAdapter -else: - from wagtail.telepath import register - from wagtail.widget_adapters import WidgetAdapter +from wagtail.telepath import register +from wagtail.widget_adapters import WidgetAdapter class PolyfillColorInputWidget(widgets.TextInput): From 3ca2980578bebd5a1133ab23e2247475216453c2 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 11:50:41 +0800 Subject: [PATCH 04/10] Linting --- tests/test_block.py | 3 +-- tests/test_field.py | 3 +-- tests/test_widget.py | 3 +-- tests/testapp/migrations/0001_initial.py | 1 - .../0002_alter_pagewithstreamfield_body.py | 3 +-- tests/testapp/models.py | 21 ++++++++----------- tests/urls.py | 3 +-- wagtail_color_panel/blocks.py | 3 +-- wagtail_color_panel/edit_handlers.py | 4 ++-- wagtail_color_panel/widgets.py | 3 +-- 10 files changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/test_block.py b/tests/test_block.py index 6f66bfd..ad23550 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -1,11 +1,10 @@ from django.core.exceptions import ValidationError from django.test import TestCase +from wagtail.test.utils import WagtailTestUtils from wagtail_color_panel.blocks import NativeColorBlock from wagtail_color_panel.widgets import ColorInputWidget -from wagtail.test.utils import WagtailTestUtils - class BlockTest(TestCase, WagtailTestUtils): def test_color_block_render(self): diff --git a/tests/test_field.py b/tests/test_field.py index 4ef63a2..638451f 100644 --- a/tests/test_field.py +++ b/tests/test_field.py @@ -1,13 +1,12 @@ from django.core.exceptions import ValidationError from django.test import TestCase +from wagtail.test.utils import WagtailTestUtils from tests.testapp.factories import ( PageWithColorFieldPageFactory, PageWithDefaultValuePageFactory, ) -from wagtail.test.utils import WagtailTestUtils - class FieldTest(TestCase, WagtailTestUtils): def test_strings_larger_than_7_raises_error(self): diff --git a/tests/test_widget.py b/tests/test_widget.py index 6b19669..0c928c3 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -1,11 +1,10 @@ from django.test import TestCase +from wagtail.test.utils import WagtailTestUtils from tests.testapp.factories import PageWithColorFieldPageFactory from wagtail_color_panel.edit_handlers import NativeColorPanel from wagtail_color_panel.widgets import ColorInputWidget -from wagtail.test.utils import WagtailTestUtils - # from wagtail.admin.panels import get_form_for_model # from wagtail.admin.forms import WagtailAdminModelForm, WagtailAdminPageForm diff --git a/tests/testapp/migrations/0001_initial.py b/tests/testapp/migrations/0001_initial.py index 1596697..855af4d 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/tests/testapp/migrations/0001_initial.py @@ -8,7 +8,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ diff --git a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py index 35644fb..6548335 100644 --- a/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py +++ b/tests/testapp/migrations/0002_alter_pagewithstreamfield_body.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - dependencies = [ ("testapp", "0001_initial"), ] @@ -18,6 +17,6 @@ class Migration(migrations.Migration): field=wagtail_fields.StreamField( [("color", wagtail_color_panel.blocks.NativeColorBlock())], use_json_field=True, - ) + ), ), ] diff --git a/tests/testapp/models.py b/tests/testapp/models.py index ce323e5..dacdf2f 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -1,14 +1,13 @@ from django.db import models - -from wagtail_color_panel.blocks import NativeColorBlock -from wagtail_color_panel.edit_handlers import NativeColorPanel -from wagtail_color_panel.fields import ColorField - from wagtail.admin.panels import FieldPanel from wagtail.admin.panels import FieldPanel as StreamFieldPanel from wagtail.fields import StreamField from wagtail.models import Page +from wagtail_color_panel.blocks import NativeColorBlock +from wagtail_color_panel.edit_handlers import NativeColorPanel +from wagtail_color_panel.fields import ColorField + class PageWithColorField(Page): color = ColorField() @@ -35,13 +34,11 @@ class PageWithDefaultValue(Page): class PageWithStreamfield(Page): - body = ( - StreamField( - [ - ("color", NativeColorBlock()), - ], - use_json_field=True, - ) + body = StreamField( + [ + ("color", NativeColorBlock()), + ], + use_json_field=True, ) content_panels = Page.content_panels + [ diff --git a/tests/urls.py b/tests/urls.py index 94196bb..1b41f46 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,7 +1,6 @@ from django.urls import include, path -from wagtail.admin import urls as wagtailadmin_urls - from wagtail import urls as wagtail_urls +from wagtail.admin import urls as wagtailadmin_urls urlpatterns = [ path("admin/", include(wagtailadmin_urls)), diff --git a/wagtail_color_panel/blocks.py b/wagtail_color_panel/blocks.py index 641a917..04c6c88 100644 --- a/wagtail_color_panel/blocks.py +++ b/wagtail_color_panel/blocks.py @@ -1,11 +1,10 @@ from django import forms from django.utils.functional import cached_property +from wagtail.blocks import FieldBlock from wagtail_color_panel.validators import hex_triplet_validator from wagtail_color_panel.widgets import ColorInputWidget -from wagtail.blocks import FieldBlock - class NativeColorBlock(FieldBlock): def __init__(self, required=True, help_text=None, validators=(), **kwargs): diff --git a/wagtail_color_panel/edit_handlers.py b/wagtail_color_panel/edit_handlers.py index 654ee17..2eaca13 100644 --- a/wagtail_color_panel/edit_handlers.py +++ b/wagtail_color_panel/edit_handlers.py @@ -1,7 +1,7 @@ -from wagtail_color_panel.widgets import ColorInputWidget, PolyfillColorInputWidget - from wagtail.admin.panels import FieldPanel +from wagtail_color_panel.widgets import ColorInputWidget, PolyfillColorInputWidget + class NativeColorPanel(FieldPanel): def widget_overrides(self): diff --git a/wagtail_color_panel/widgets.py b/wagtail_color_panel/widgets.py index abfd1c0..e1db39e 100644 --- a/wagtail_color_panel/widgets.py +++ b/wagtail_color_panel/widgets.py @@ -2,9 +2,8 @@ from django.forms import widgets from django.utils.safestring import mark_safe -from wagtail.utils.widgets import WidgetWithScript - from wagtail.telepath import register +from wagtail.utils.widgets import WidgetWithScript from wagtail.widget_adapters import WidgetAdapter From b4a0c623e642fadec688c36119ad952a75d54231 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 12:08:31 +0800 Subject: [PATCH 05/10] Cleanup code for older versions of Wagtail (< 4.1) --- tests/testapp/models.py | 3 +-- wagtail_color_panel/edit_handlers.py | 21 ++++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/testapp/models.py b/tests/testapp/models.py index dacdf2f..7c798ff 100644 --- a/tests/testapp/models.py +++ b/tests/testapp/models.py @@ -1,6 +1,5 @@ from django.db import models from wagtail.admin.panels import FieldPanel -from wagtail.admin.panels import FieldPanel as StreamFieldPanel from wagtail.fields import StreamField from wagtail.models import Page @@ -42,5 +41,5 @@ class PageWithStreamfield(Page): ) content_panels = Page.content_panels + [ - StreamFieldPanel("body"), + FieldPanel("body"), ] diff --git a/wagtail_color_panel/edit_handlers.py b/wagtail_color_panel/edit_handlers.py index 2eaca13..ae16e65 100644 --- a/wagtail_color_panel/edit_handlers.py +++ b/wagtail_color_panel/edit_handlers.py @@ -4,27 +4,18 @@ class NativeColorPanel(FieldPanel): - def widget_overrides(self): - # For Wagtail<3.0 we use widget_overrides - return { - self.field_name: ColorInputWidget(), - } - def get_form_options(self): - # For Wagtail 3.0 we use get_form_options - # So we can mix them to provide supports to Wagtail 2,3 opts = super().get_form_options() - opts["widgets"] = self.widget_overrides() + opts["widgets"] = { + self.field_name: ColorInputWidget(), + } return opts class PolyfillColorPanel(FieldPanel): - def widget_overrides(self): - return { - self.field_name: PolyfillColorInputWidget(), - } - def get_form_options(self): opts = super().get_form_options() - opts["widgets"] = self.widget_overrides() + opts["widgets"] = { + self.field_name: PolyfillColorInputWidget(), + } return opts From 9718e844f140f7f133943c31d0d325af52391bb3 Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Wed, 14 Jun 2023 12:12:08 +0800 Subject: [PATCH 06/10] Fix failing test --- tests/test_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_widget.py b/tests/test_widget.py index 0c928c3..7bf9323 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -25,5 +25,5 @@ def test_native_color_panel_uses_correct_widget(self): color_panel = page.content_panels[1] self.assertEqual(color_panel.__class__, NativeColorPanel) - color_widget = color_panel.widget_overrides()["color"] + color_widget = color_panel.get_form_options()["widgets"]["color"] self.assertEqual(color_widget.__class__, ColorInputWidget) From e58bffa8be77f830d0fa0850d3d189d0ab2fb21f Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 5 Oct 2023 17:51:31 +0800 Subject: [PATCH 07/10] Add tests for Wagtail 5.1 on main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 87da4c0..46ca21c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ jobs: - "4.1" - "4.2" - "5.0" + - "5.1" exclude: - python-version: "3.11" wagtail-version: "4.1" From d746843cdfd0bd9e96f190a211a2c3578e85e66c Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Thu, 5 Oct 2023 17:51:41 +0800 Subject: [PATCH 08/10] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb998f8..0102fb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Add Wagtail 5.0 support (@katdom13) +- Add Wagtail >= 5.0 support (@katdom13) - Add Python 4.2 support (@katdom13) -- Add Python 3.11 support +- Add Python 3.11 support (@katdom13) ### Changed ### Fixed From 424c5303873cb6db495978569c7b139ea754961c Mon Sep 17 00:00:00 2001 From: Katherine Domingo Date: Tue, 14 Nov 2023 16:10:18 +0800 Subject: [PATCH 09/10] Add Wagtail 5.2 to the test workflow --- .github/workflows/main.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 46ca21c..99516f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,11 +17,7 @@ jobs: - "4.2" - "5.0" - "5.1" - exclude: - - python-version: "3.11" - wagtail-version: "4.1" - - python-version: "3.11" - wagtail-version: "4.2" + - "5.2" steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} From 073011157197d1b543c1624408352c6f698eb74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Fri, 22 Dec 2023 05:46:32 +0100 Subject: [PATCH 10/10] Bump version --- CHANGELOG.md | 9 ++++++--- wagtail_color_panel/__init__.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0102fb0..8239917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +### Changed +### Fixed +### Removed + +## [1.5.0] - 2023-12-22 +### Added - Add Wagtail >= 5.0 support (@katdom13) -- Add Python 4.2 support (@katdom13) - Add Python 3.11 support (@katdom13) -### Changed -### Fixed ### Removed - Drop Wagtail < 4.1 support (@katdom13) - Drop Django 4.0 support (@katdom13) diff --git a/wagtail_color_panel/__init__.py b/wagtail_color_panel/__init__.py index 57fbe43..9b01a68 100644 --- a/wagtail_color_panel/__init__.py +++ b/wagtail_color_panel/__init__.py @@ -1,6 +1,6 @@ __title__ = "wagtail_color_panel" -__version__ = "1.4.1" -__build__ = 8 +__version__ = "1.5.0" +__build__ = 9 __author__ = "Martin Sandström" __license__ = "MIT" __copyright__ = "Copyright 2020-present Martin Sandström"