Skip to content

Commit

Permalink
Merge pull request #6 from torchbox-forks/support/wagtail-60
Browse files Browse the repository at this point in the history
Wagtail 6.0
  • Loading branch information
katdom13 authored Mar 6, 2024
2 parents a63531d + 536c8fe commit 6ed3139
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 38 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
wagtail-version:
- "4.1"
- "4.2"
- "5.0"
- "5.1"
- "5.2"
- "6.0"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -37,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "--check --verbose"
Expand All @@ -48,8 +46,8 @@ jobs:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
Expand All @@ -62,8 +60,8 @@ jobs:
runs-on: ubuntu-latest
needs: [test, lint-black, lint-isort]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Add Wagtail 6.0 support (@katdom13)
- Add Python 3.11 support (@katdom13)

### Changed
### Fixed
- Apply Django 5.0 upgrade considerations (@katdom13)

### Removed
- Drop Wagtail < 5.2 support (@katdom13)

## [1.5.0] - 2023-12-22
### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/1_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Requirements

- Python 3.8+
- Wagtail 4.1+ and Django 3.2+
- Wagtail 5.2+ and Django 3.2+
- [A browser that supports `input type="color"`](https://caniuse.com/#feat=input-color)


Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import find_packages, setup

install_requires = ["wagtail>=4.1"]
install_requires = ["wagtail>=5.2"]

tests_require = ["pytest-django", "wagtail-factories", "pytest"]

Expand Down Expand Up @@ -39,9 +39,12 @@
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Expand All @@ -51,6 +54,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Utilities",
],
setup_requires=["setuptools_scm", "pytest-runner"],
Expand Down
8 changes: 7 additions & 1 deletion tests/test_block.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.test.utils import WagtailTestUtils

from wagtail_color_panel.blocks import NativeColorBlock
Expand All @@ -15,8 +16,13 @@ def test_color_block_render(self):

def test_form_uses_proper_input_type(self):
block = NativeColorBlock()
html = block.field.widget.render_html(name="cat", value="#333333", attrs={})

if WAGTAIL_VERSION >= (6, 0):
html = block.field.widget.render(name="cat", value="#333333", attrs={})
else:
html = block.field.widget.render_html(name="cat", value="#333333", attrs={})

print(html)
self.assertEqual(block.field.widget.__class__, ColorInputWidget)
self.assertIn('type="color"', html)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// wagtail_color_panel/static/wagtail_color_panel/js/color-input-controller.js

class ColorInputController extends window.StimulusModule.Controller {
connect() {
new ColorInputWidget(this.element.id);
}
}

window.wagtail.app.register('read-only-uuid', ColorInputController);
80 changes: 58 additions & 22 deletions wagtail_color_panel/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.forms import widgets
from django.utils.safestring import mark_safe
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.telepath import register
from wagtail.utils.widgets import WidgetWithScript
from wagtail.widget_adapters import WidgetAdapter


Expand Down Expand Up @@ -49,29 +49,65 @@ def render(self, name, value, attrs=None, renderer=None):
)


class ColorInputWidget(WidgetWithScript, widgets.TextInput):
template_name = "wagtail_color_panel/widgets/color-input-widget.html"

def __init__(self, attrs=None):
default_attrs = {
"class": "color-input-widget__text-input",
}
attrs = attrs or {}
attrs = {**default_attrs, **attrs}
super().__init__(attrs=attrs)

def render_js_init(self, id_, name, value):
return "new ColorInputWidget({0});".format(json.dumps(id_))
if WAGTAIL_VERSION >= (6, 0): # type: ignore
from django.forms import Media

class ColorInputWidget(widgets.TextInput): # type: ignore
template_name = "wagtail_color_panel/widgets/color-input-widget.html"

def __init__(self, attrs=None):
default_attrs = {
"class": "color-input-widget__text-input",
}
attrs = attrs or {}
attrs = {**default_attrs, **attrs}
super().__init__(attrs=attrs)

def build_attrs(self, *args, **kwargs):
attrs = super().build_attrs(*args, **kwargs)
attrs["data-controller"] = "color-input"
return attrs

@property
def media(self):
return Media(
css={
"all": [
"wagtail_color_panel/css/color-input-widget.css",
]
},
js=[
"wagtail_color_panel/js/color-input-widget.js",
"wagtail_color_panel/js/color-input-controller.js",
],
)

class Media:
css = {
"all": [
"wagtail_color_panel/css/color-input-widget.css",
else:
from wagtail.utils.widgets import WidgetWithScript

class ColorInputWidget(WidgetWithScript, widgets.TextInput):
template_name = "wagtail_color_panel/widgets/color-input-widget.html"

def __init__(self, attrs=None):
default_attrs = {
"class": "color-input-widget__text-input",
}
attrs = attrs or {}
attrs = {**default_attrs, **attrs}
super().__init__(attrs=attrs)

def render_js_init(self, id_, name, value):
return "new ColorInputWidget({0});".format(json.dumps(id_))

class Media:
css = {
"all": [
"wagtail_color_panel/css/color-input-widget.css",
]
}
js = [
"wagtail_color_panel/js/color-input-widget.js",
]
}
js = [
"wagtail_color_panel/js/color-input-widget.js",
]


class ColorInputWidgetAdapter(WidgetAdapter):
Expand Down

0 comments on commit 6ed3139

Please sign in to comment.