From 8a478e5af0b618697e5f2a4578c57f5d907e9c17 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 11 Jan 2023 10:37:20 -0500 Subject: [PATCH 01/12] Switch to pyproject.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With [PEP 621 support added to setuptools](pypa/setuptools#2970) last year, and with pip supporting editable installs as of 21.3, we can move to `pyproject.toml` and deprecate `setup.py`. The file remains for legacy pip support. Because [flake8 does not want to support pyproject.tml yet](PyCQA/flake8#234), unlike all the other tools we use, I’m removing it in favor of [ruff](https://github.com/charliermarsh/ruff). Co-authored-by: Andy Chosak --- .github/workflows/test.yml | 28 ++++++------ .pre-commit-config.yaml | 7 ++- pyproject.toml | 91 ++++++++++++++++++++++++++++++++++---- setup.cfg | 76 ------------------------------- tox.ini | 18 ++++---- 5 files changed, 109 insertions(+), 111 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4b923d..472dfe9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.8" - name: Install dependencies run: | @@ -33,22 +33,22 @@ jobs: matrix: toxenv: # Legacy versions - - py39-dj32-wag215 + - py38-dj32-wag215 # Current and latest versions - - py310-dj32-wag30 - - py310-dj40-wag30 - - py310-dj40-waglatest + - py311-dj32-wag30 + - py311-dj40-wag30 + - py311-dj40-waglatest include: - - toxenv: py39-dj32-wag215 - python-version: "3.9" - - toxenv: py310-dj32-wag30 - python-version: "3.10" - - toxenv: py310-dj40-wag30 - python-version: "3.10" - - toxenv: py310-dj40-waglatest - python-version: "3.10" + - toxenv: py38-dj32-wag215 + python-version: "3.8" + - toxenv: py311-dj32-wag30 + python-version: "3.11" + - toxenv: py311-dj40-wag30 + python-version: "3.11" + - toxenv: py311-dj40-waglatest + python-version: "3.11" steps: - uses: actions/checkout@v3 @@ -89,7 +89,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.8" - name: Install dependencies run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b7efd01..d00e5b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,10 @@ repos: - id: black args: ["wagtailflags", "setup.py", "--line-length=79"] exclude: migrations -- repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.188 hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear==22.1.11] + - id: ruff - repo: https://github.com/pycqa/isort rev: 5.10.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index d237113..5fabc52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,55 @@ +[project] +name = "wagtail-flags" +version = "5.3.0" +description = "Feature flags for Wagtail sites" +readme = "README.md" +requires-python = ">=3.8" +license = {text = "CC0"} +authors = [ + {name = "CFPB", email = "tech@cfpb.gov" } +] +dependencies = [ + "wagtail>2.15,<4", + "django-flags>4.2" +] +classifiers = [ + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4", + "Framework :: Wagtail", + "Framework :: Wagtail :: 2", + "Framework :: Wagtail :: 3", + "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", + "License :: Public Domain", + "Programming Language :: Python", + "Programming Language :: Python :: 3", +] + +[project.optional-dependencies] +testing = [ + "coverage[toml]", +] + +[project.urls] +"Homepage" = "https://github.com/cfpb/wagtail-flags" +"Bug Reports" = "https://github.com/cfpb/wagtail-flags/issues" +"Source" = "https://github.com/cfpb/wagtail-flags" + +[build-system] +requires = ["setuptools>=43.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.package-data] +wagtailflags = [ + "templates/wagtailflags/*", + "templates/wagtailflags/flags/*", + "templates/wagtailflags/includes/*", + "static/wagtailflags/css/*", +] + [tool.black] line-length = 79 -target-version = ['py36', 'py38'] +target-version = ["py38"] include = '\.pyi?$' exclude = ''' ( @@ -14,15 +63,41 @@ exclude = ''' | dist | migrations | site - | \*.json - | \*.csv )/ ) ''' -[build-system] -requires = [ - "setuptools>=42", - "wheel" +[tool.isort] +profile = "black" +line_length = 79 +lines_after_imports = 2 +skip = [".tox", ".venv", "venv"] +known_django = ["django"] +known_wagtail = ["wagtail"] +default_section = "THIRDPARTY" +sections = [ + "STDLIB", + "DJANGO", + "WAGTAIL", + "THIRDPARTY", + "FIRSTPARTY", + "LOCALFOLDER" +] + +[tool.ruff] +exclude = [ + ".git", + ".tox", + "__pycache__", +] +ignore = [] +select = [ + "E", + "F", + "W", +] + +[tool.coverage.run] +omit = [ + "wagtailflags/tests/*", ] -build-backend = "setuptools.build_meta" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index b2edf83..0000000 --- a/setup.cfg +++ /dev/null @@ -1,76 +0,0 @@ -[metadata] -name = wagtail-flags -version = 5.2.0 -author = CFPB -author_email = tech@cfpb.gov -description = Feature flags for Wagtail sites -long_description = file: README.md -long_description_content_type = text/markdown -license = CC0 -url = https://github.com/cfpb/wagtail-flags -classifiers = - Operating System :: OS Independent - Framework :: Django - Framework :: Django :: 3.2 - Framework :: Django :: 4.0 - Framework :: Wagtail - Framework :: Wagtail :: 2 - Framework :: Wagtail :: 3 - License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication - License :: Public Domain - Programming Language :: Python - Programming Language :: Python :: 3 - -[options] -include_package_data = True -packages = find: -python_requires = >=3.8 -zip_safe = False -install_requires = - wagtail>=2.15,<4 - django-flags>=4.2,<5.1 - -[options.extras_require] -testing = - coverage - -[flake8] -ignore = E731,W503,W504 -exclude = - .git, - .tox, - __pycache__, - */migrations/*.py, - .eggs/*, - -[isort] -profile = black -combine_as_imports = 1 -lines_after_imports = 2 -include_trailing_comma = 1 -multi_line_output = 3 -skip = .tox,migrations -known_django = django -known_wagtail = wagtail -default_section = THIRDPARTY -sections = FUTURE,STDLIB,DJANGO,WAGTAIL,THIRDPARTY,FIRSTPARTY,LOCALFOLDER - -[mypy] -allow_redefinition = false -check_untyped_defs = true -disallow_untyped_decorators = true -disallow_any_explicit = true -disallow_any_generics = true -disallow_untyped_calls = true -ignore_errors = false -ignore_missing_imports = true -implicit_reexport = false -local_partial_types = true -strict_optional = true -strict_equality = true -no_implicit_optional = true -warn_unused_ignores = true -warn_redundant_casts = true -warn_unused_configs = true -warn_unreachable = true -warn_no_return = true diff --git a/tox.ini b/tox.ini index 0bc1cb8..8e0cf0f 100644 --- a/tox.ini +++ b/tox.ini @@ -2,8 +2,8 @@ skipsdist=True envlist= lint, - py{39,310}-dj{32}-wag{215}, - py{39,310}-dj{32,40}-wag{30,latest}, + py{38,311}-dj{32}-wag{215}, + py{38,311}-dj{32,40}-wag{30,latest}, coverage [testenv] @@ -14,29 +14,29 @@ setenv= DJANGO_SETTINGS_MODULE=wagtailflags.tests.settings basepython= - py39: python3.9 - py310: python3.10 + py38: python3.8 + py311: python3.11 deps= dj32: Django>=3.2,<3.3 dj40: Django>=4.0,<4.1 - wag215: wagtail>=2.15,<2.16 + wag215: wagtail>=2.15,<4 wag30: wagtail>=3.0,<3.1 waglatest: wagtail<4 [testenv:lint] -basepython=python3.10 +basepython=python3.8 deps= black - flake8 + ruff isort commands= black --check wagtailflags - flake8 wagtailflags + ruff wagtailflags isort --check-only --diff wagtailflags [testenv:coverage] -basepython=python3.10 +basepython=python3.8 deps= coverage diff_cover From 0814b0d1832d4d2a81eec7304a3702f2179252b1 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 11 Jan 2023 10:57:14 -0500 Subject: [PATCH 02/12] Add interactive tox environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new `tox -e interactive` that runs a local test server, to make it easier to test this project. This is a feature that [wagtail-localize](https://www.wagtail-localize.org/#how-to-run-tests) has that we’ve also added to [wagtail-inventory](https://github.com/cfpb/wagtail-inventory#testing) and [wagtail-treemodeladmin](https://github.com/cfpb/wagtail-treemodeladmin). 🎩 to @chosak for this pattern. Co-authored-by: Andy Chosak --- .gitignore | 1 + tox.ini | 18 ++++++++++++++++ wagtailflags/tests/settings.py | 38 ++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 9f36985..429da40 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,4 @@ dist/ # IDEs .idea/ +*.db diff --git a/tox.ini b/tox.ini index 8e0cf0f..86e10cd 100644 --- a/tox.ini +++ b/tox.ini @@ -44,3 +44,21 @@ commands= coverage combine coverage xml diff-cover coverage.xml --compare-branch=origin/main --fail-under=100 + +[testenv:interactive] +basepython=python3.8 + +deps= + Django>=3.2,<3.3 + +commands_pre= + {envbindir}/django-admin makemigrations + {envbindir}/django-admin migrate + {envbindir}/django-admin shell -c "from django.contrib.auth.models import User;(not User.objects.filter(username='admin').exists()) and User.objects.create_superuser('admin', 'super@example.com', 'changeme')" + +commands= + {posargs:{envbindir}/django-admin runserver 0.0.0.0:8000} + +setenv= + DJANGO_SETTINGS_MODULE=wagtailflags.tests.settings + INTERACTIVE=1 diff --git a/wagtailflags/tests/settings.py b/wagtailflags/tests/settings.py index 5b9843b..c2c920b 100644 --- a/wagtailflags/tests/settings.py +++ b/wagtailflags/tests/settings.py @@ -3,9 +3,12 @@ import wagtail +DEBUG = True + ALLOWED_HOSTS = ["*"] USE_TZ = True + SECRET_KEY = "not needed" ROOT_URLCONF = "wagtailflags.tests.urls" @@ -23,12 +26,6 @@ }, } -INSTALLED_APPS = ( - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", -) - WAGTAIL_APPS = ( "wagtail.contrib.forms", "wagtail.contrib.modeladmin", @@ -36,32 +33,37 @@ "wagtail.admin", "wagtail.documents", "wagtail.images", + "wagtail.snippets", "wagtail.sites", "wagtail.users", ) -WAGTAILADMIN_RICH_TEXT_EDITORS = { - "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, -} - # Wagtail 3.0 moves testapp from wagtail.tests to wagtail.test if wagtail.VERSION >= (3, 0, 0): # pragma: no cover WAGTAIL_APPS += ( "wagtail", "wagtail.test.testapp", ) - WAGTAILADMIN_RICH_TEXT_EDITORS["custom"] = { - "WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea" + WAGTAILADMIN_RICH_TEXT_EDITORS = { + "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, + "custom": { + "WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea" + }, } else: # pragma: no cover WAGTAIL_APPS += ( "wagtail.core", "wagtail.tests.testapp", ) - WAGTAILADMIN_RICH_TEXT_EDITORS["custom"] = { - "WIDGET": "wagtail.tests.testapp.rich_text.CustomRichTextArea" + WAGTAILADMIN_RICH_TEXT_EDITORS = { + "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, + "custom": { + "WIDGET": "wagtail.tests.testapp.rich_text.CustomRichTextArea" + }, } +WAGTAILADMIN_BASE_URL = "http://localhost:8000" + MIDDLEWARE = ( "django.middleware.common.CommonMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", @@ -71,6 +73,13 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ) +INSTALLED_APPS = ( + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", +) + + INSTALLED_APPS = ( ( "django.contrib.admin", @@ -88,7 +97,6 @@ ) ) -STATIC_ROOT = "/tmp/static/" STATIC_URL = "/static/" TEMPLATES = [ From 17e7d9c20e1bb175266a853976e3fd02a03227a0 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Thu, 12 Jan 2023 09:24:50 -0500 Subject: [PATCH 03/12] Update release to PyPI workflow --- .github/workflows/release.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3677496..94954db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,26 +1,28 @@ name: Publish to PyPI -on: +on: release: types: [published] + workflow_dispatch: + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.11 - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip build pip install twine wheel - name: Build the package run: | - python setup.py sdist bdist_wheel --universal + python -m build - name: Upload to PyPI run: twine upload dist/* - env: + env: TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} From 277a1107670411fed1baad6007e1500395eeb97d Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 18 Jan 2023 11:07:14 -0500 Subject: [PATCH 04/12] =?UTF-8?q?Use=20CFPB=E2=80=99s=20flag=20icon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds the flag icon from CFPB’s [Design System](https://cfpb.github.io/design-system/foundation/iconography) as a custom icon, and uses it in the Wagtail admin. --- wagtailflags/templates/wagtailflags/flag.svg | 1 + wagtailflags/wagtail_hooks.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 wagtailflags/templates/wagtailflags/flag.svg diff --git a/wagtailflags/templates/wagtailflags/flag.svg b/wagtailflags/templates/wagtailflags/flag.svg new file mode 100644 index 0000000..09d16bd --- /dev/null +++ b/wagtailflags/templates/wagtailflags/flag.svg @@ -0,0 +1 @@ + diff --git a/wagtailflags/wagtail_hooks.py b/wagtailflags/wagtail_hooks.py index 4884620..26b9d53 100644 --- a/wagtailflags/wagtail_hooks.py +++ b/wagtailflags/wagtail_hooks.py @@ -21,7 +21,7 @@ def register_flags_menu(): return MenuItem( "Flags", reverse("wagtailflags:list"), - icon_name="tag", + icon_name="flag", order=10000, ) @@ -80,3 +80,8 @@ def global_admin_css(): '', static("wagtailflags/css/wagtailflags.css"), ) + + +@hooks.register("register_icons") +def register_icons(icons): + return icons + ["wagtailflags/flag.svg"] From 705181fada74080e466fd41e17475b4a27bb73f8 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 18 Jan 2023 11:09:13 -0500 Subject: [PATCH 05/12] Remove checks for Wagtail > 3 --- wagtailflags/tests/test_conditions.py | 5 +---- wagtailflags/tests/test_signals.py | 5 +---- wagtailflags/tests/test_views.py | 5 +---- wagtailflags/wagtail_hooks.py | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/wagtailflags/tests/test_conditions.py b/wagtailflags/tests/test_conditions.py index 1fd0b18..0e1bc2e 100644 --- a/wagtailflags/tests/test_conditions.py +++ b/wagtailflags/tests/test_conditions.py @@ -7,10 +7,7 @@ from wagtailflags.conditions import site_condition -if wagtail.VERSION > (3, 0, 0): # pragma: no cover - from wagtail.models import Site -else: # pragma: no cover - from wagtail.core.models import Site +from wagtail.models import Site class SiteConditionTestCase(TestCase): diff --git a/wagtailflags/tests/test_signals.py b/wagtailflags/tests/test_signals.py index 8e30acb..1bca664 100644 --- a/wagtailflags/tests/test_signals.py +++ b/wagtailflags/tests/test_signals.py @@ -9,10 +9,7 @@ from wagtailflags.signals import flag_disabled, flag_enabled -if wagtail.VERSION >= (3, 0, 0): # pragma: no cover - from wagtail.test.utils import WagtailTestUtils -else: # pragma: no cover - from wagtail.tests.utils import WagtailTestUtils +from wagtail.test.utils import WagtailTestUtils class SignalsTestCase(TestCase, WagtailTestUtils): diff --git a/wagtailflags/tests/test_views.py b/wagtailflags/tests/test_views.py index ecb04de..a5df4ff 100644 --- a/wagtailflags/tests/test_views.py +++ b/wagtailflags/tests/test_views.py @@ -5,10 +5,7 @@ from flags.models import FlagState -if wagtail.VERSION >= (3, 0, 0): # pragma: no cover - from wagtail.test.utils import WagtailTestUtils -else: # pragma: no cover - from wagtail.tests.utils import WagtailTestUtils +from wagtail.test.utils import WagtailTestUtils class TestWagtailFlagsViews(TestCase, WagtailTestUtils): diff --git a/wagtailflags/wagtail_hooks.py b/wagtailflags/wagtail_hooks.py index 26b9d53..bf43cf1 100644 --- a/wagtailflags/wagtail_hooks.py +++ b/wagtailflags/wagtail_hooks.py @@ -8,10 +8,7 @@ from wagtailflags import views -if wagtail.VERSION >= (3, 0, 0): # pragma: no cover - from wagtail import hooks -else: # pragma: no cover - from wagtail.core import hooks +from wagtail import hooks from django.urls import include, re_path, reverse From 05418b045a0a48039e48e89ad228f0e1a08aced9 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 18 Jan 2023 11:53:39 -0500 Subject: [PATCH 06/12] Update project scaffolding for Wagtail 4 --- .github/workflows/test.yml | 27 ++++++++++++--------------- pyproject.toml | 5 ++--- setup.py | 3 ++- tox.ini | 12 +++++------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 472dfe9..153a046 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,23 +32,20 @@ jobs: strategy: matrix: toxenv: - # Legacy versions - - py38-dj32-wag215 - - # Current and latest versions - - py311-dj32-wag30 - - py311-dj40-wag30 - - py311-dj40-waglatest + - py38-dj3-wag4 + - py38-dj4-wag4 + - py38-dj3-waglatest + - py38-dj4-waglatest include: - - toxenv: py38-dj32-wag215 - python-version: "3.8" - - toxenv: py311-dj32-wag30 - python-version: "3.11" - - toxenv: py311-dj40-wag30 - python-version: "3.11" - - toxenv: py311-dj40-waglatest - python-version: "3.11" + - toxenv: py38-dj3-wag4 + python-version: 3.8 + - toxenv: py38-dj4-wag4 + python-version: 3.8 + - toxenv: py38-dj3-waglatest + python-version: 3.8 + - toxenv: py38-dj4-waglatest + python-version: 3.8 steps: - uses: actions/checkout@v3 diff --git a/pyproject.toml b/pyproject.toml index 5fabc52..3641b94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = [ {name = "CFPB", email = "tech@cfpb.gov" } ] dependencies = [ - "wagtail>2.15,<4", + "wagtail>=4", "django-flags>4.2" ] classifiers = [ @@ -17,8 +17,7 @@ classifiers = [ "Framework :: Django :: 3.2", "Framework :: Django :: 4", "Framework :: Wagtail", - "Framework :: Wagtail :: 2", - "Framework :: Wagtail :: 3", + "Framework :: Wagtail :: 4", "License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication", "License :: Public Domain", "Programming Language :: Python", diff --git a/setup.py b/setup.py index 6b40b52..26e08e4 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from setuptools import setup -if __name__ == '__main__': + +if __name__ == "__main__": setup() diff --git a/tox.ini b/tox.ini index 86e10cd..9167ca4 100644 --- a/tox.ini +++ b/tox.ini @@ -2,8 +2,7 @@ skipsdist=True envlist= lint, - py{38,311}-dj{32}-wag{215}, - py{38,311}-dj{32,40}-wag{30,latest}, + py{38,311}-dj{3,4}-wag{4,latest}, coverage [testenv] @@ -18,11 +17,10 @@ basepython= py311: python3.11 deps= - dj32: Django>=3.2,<3.3 - dj40: Django>=4.0,<4.1 - wag215: wagtail>=2.15,<4 - wag30: wagtail>=3.0,<3.1 - waglatest: wagtail<4 + dj3: Django>=3.2,<4 + dj4: Django>=4.1,<5 + wag4: wagtail>=4,<5 + waglatest: wagtail>4 [testenv:lint] basepython=python3.8 From 1448448648a414bba4015643d025756fa7cdb3ce Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 18 Jan 2023 11:54:14 -0500 Subject: [PATCH 07/12] Remove wagtail <3 --- wagtailflags/tests/settings.py | 33 +++++++-------------------- wagtailflags/tests/test_conditions.py | 5 +--- wagtailflags/tests/test_signals.py | 5 +--- wagtailflags/tests/test_views.py | 5 +--- wagtailflags/wagtail_hooks.py | 8 ++----- 5 files changed, 13 insertions(+), 43 deletions(-) diff --git a/wagtailflags/tests/settings.py b/wagtailflags/tests/settings.py index c2c920b..0bd72f7 100644 --- a/wagtailflags/tests/settings.py +++ b/wagtailflags/tests/settings.py @@ -1,7 +1,5 @@ import os -import wagtail - DEBUG = True @@ -38,29 +36,14 @@ "wagtail.users", ) -# Wagtail 3.0 moves testapp from wagtail.tests to wagtail.test -if wagtail.VERSION >= (3, 0, 0): # pragma: no cover - WAGTAIL_APPS += ( - "wagtail", - "wagtail.test.testapp", - ) - WAGTAILADMIN_RICH_TEXT_EDITORS = { - "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, - "custom": { - "WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea" - }, - } -else: # pragma: no cover - WAGTAIL_APPS += ( - "wagtail.core", - "wagtail.tests.testapp", - ) - WAGTAILADMIN_RICH_TEXT_EDITORS = { - "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, - "custom": { - "WIDGET": "wagtail.tests.testapp.rich_text.CustomRichTextArea" - }, - } +WAGTAIL_APPS += ( + "wagtail", + "wagtail.test.testapp", +) +WAGTAILADMIN_RICH_TEXT_EDITORS = { + "default": {"WIDGET": "wagtail.admin.rich_text.DraftailRichTextArea"}, + "custom": {"WIDGET": "wagtail.test.testapp.rich_text.CustomRichTextArea"}, +} WAGTAILADMIN_BASE_URL = "http://localhost:8000" diff --git a/wagtailflags/tests/test_conditions.py b/wagtailflags/tests/test_conditions.py index 0e1bc2e..8ebbc20 100644 --- a/wagtailflags/tests/test_conditions.py +++ b/wagtailflags/tests/test_conditions.py @@ -1,15 +1,12 @@ from django.test import RequestFactory, TestCase -import wagtail +from wagtail.models import Site from flags.conditions import RequiredForCondition from wagtailflags.conditions import site_condition -from wagtail.models import Site - - class SiteConditionTestCase(TestCase): def setUp(self): self.site = Site.objects.get(is_default_site=True) diff --git a/wagtailflags/tests/test_signals.py b/wagtailflags/tests/test_signals.py index 1bca664..4313c8c 100644 --- a/wagtailflags/tests/test_signals.py +++ b/wagtailflags/tests/test_signals.py @@ -2,16 +2,13 @@ from django.test import TestCase -import wagtail +from wagtail.test.utils import WagtailTestUtils from flags.models import FlagState from wagtailflags.signals import flag_disabled, flag_enabled -from wagtail.test.utils import WagtailTestUtils - - class SignalsTestCase(TestCase, WagtailTestUtils): def setUp(self): self.login() diff --git a/wagtailflags/tests/test_views.py b/wagtailflags/tests/test_views.py index a5df4ff..f0f7926 100644 --- a/wagtailflags/tests/test_views.py +++ b/wagtailflags/tests/test_views.py @@ -1,13 +1,10 @@ from django.test import TestCase -import wagtail +from wagtail.test.utils import WagtailTestUtils from flags.models import FlagState -from wagtail.test.utils import WagtailTestUtils - - class TestWagtailFlagsViews(TestCase, WagtailTestUtils): def setUp(self): self.login() diff --git a/wagtailflags/wagtail_hooks.py b/wagtailflags/wagtail_hooks.py index bf43cf1..49239a1 100644 --- a/wagtailflags/wagtail_hooks.py +++ b/wagtailflags/wagtail_hooks.py @@ -1,18 +1,14 @@ import django from django.templatetags.static import static +from django.urls import include, re_path, reverse from django.utils.html import format_html -import wagtail +from wagtail import hooks from wagtail.admin.menu import MenuItem from wagtailflags import views -from wagtail import hooks - -from django.urls import include, re_path, reverse - - @hooks.register("register_settings_menu_item") def register_flags_menu(): return MenuItem( From 1a94a168ed394911daaac485d8aac7e7244fecd2 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Wed, 18 Jan 2023 11:57:28 -0500 Subject: [PATCH 08/12] Update admin templates for Wagtail 4 This change adds Wagtail 4 breadcrumbs and header changes, updates the Wagtail admin styled forms, and makes some minor wording modifications. It also moves edit-condition title logic from the template to the view. --- .../wagtailflags/flags/create_flag.html | 46 ++++++++++--------- .../wagtailflags/flags/delete_condition.html | 4 +- .../wagtailflags/flags/edit_condition.html | 35 +++++++------- .../wagtailflags/flags/flag_index.html | 6 +-- .../includes/flag_breadcrumbs.html | 46 +++++++++++++++++++ .../wagtailflags/includes/flag_header.html | 12 +++++ .../wagtailflags/includes/header.html | 21 +++------ .../templates/wagtailflags/index.html | 4 +- wagtailflags/views.py | 3 ++ 9 files changed, 115 insertions(+), 62 deletions(-) create mode 100644 wagtailflags/templates/wagtailflags/includes/flag_breadcrumbs.html create mode 100644 wagtailflags/templates/wagtailflags/includes/flag_header.html diff --git a/wagtailflags/templates/wagtailflags/flags/create_flag.html b/wagtailflags/templates/wagtailflags/flags/create_flag.html index 1b38d34..5012174 100644 --- a/wagtailflags/templates/wagtailflags/flags/create_flag.html +++ b/wagtailflags/templates/wagtailflags/flags/create_flag.html @@ -3,33 +3,37 @@ {% block titletag %}Create a flag{% endblock %} {% block content %} - {% include "wagtailadmin/shared/header.html" with title=flag.name icon="tag" %} - -

- Create a flag -

+ {% trans "Create a flag" as create_flags_str %} + {% include "wagtailadmin/shared/header.html" with title=create_flags_str icon="flag" %}
{% csrf_token %}
    -
  • - {% for field in form %} - {% if field.errors %} -
    - {{ field.errors }} -
    - {% endif %} - -
    -
    - {{ field }} - + {% for field in form %} +
  • +
    + +
    +
    + + {% if field.errors %} +
    + {{ field.errors }} +
    + {% endif %} +
    +
    + {{ field }} + +
    -

    - {% endfor %} -
  • -
  • +
  • + {% endfor %} + +
  • {% icon name="cog" wrapped=1 %} Back to flags
  • diff --git a/wagtailflags/templates/wagtailflags/flags/delete_condition.html b/wagtailflags/templates/wagtailflags/flags/delete_condition.html index 82cf502..3e8e2e4 100644 --- a/wagtailflags/templates/wagtailflags/flags/delete_condition.html +++ b/wagtailflags/templates/wagtailflags/flags/delete_condition.html @@ -1,9 +1,9 @@ {% extends "wagtailadmin/base.html" %} {% load i18n feature_flags %} -{% block titletag %}{% trans "Delete" as delete_str %}: {{ flag_id }}{% endblock %} +{% block titletag %}{% trans "Delete condition" as delete_str %} {{ delete_str }}: {{ condition_str }}{% endblock %} {% block content %} - {% trans "Delete flag condition:" as delete_str %} + {% trans "Delete condition" as delete_str %} {% include "wagtailadmin/shared/header.html" with title=delete_str subtitle=condition_str %} diff --git a/wagtailflags/templates/wagtailflags/flags/edit_condition.html b/wagtailflags/templates/wagtailflags/flags/edit_condition.html index a9657d4..a6a1e4a 100644 --- a/wagtailflags/templates/wagtailflags/flags/edit_condition.html +++ b/wagtailflags/templates/wagtailflags/flags/edit_condition.html @@ -1,13 +1,10 @@ {% extends "wagtailadmin/base.html" %} {% load i18n feature_flags wagtailadmin_tags %} -{% block titletag %}{% if form.instance %}Edit {{ form.instance.condition }} condition{% else %}Create condition{% endif %}{% endblock %} -{% block content %} - {% include "wagtailadmin/shared/header.html" with title=flag.name icon="tag" %} +{% block titletag %}{{ title }}{% endblock %} -

    - {% if form.instance %}Edit {{ form.instance.condition }}{% else %}Create condition{% endif %} -

    +{% block content %} + {% include "wagtailadmin/shared/header.html" with title=title icon="flag" %} {% if condition_pk %} @@ -20,34 +17,34 @@

    {% for field in form %}
  • {% if not field.is_hidden %} -
    - {{ field.label_tag }} -
    -
    - {{ field }} -
    - {% if field.help_text %} -

    {{ field.help_text|safe }}

    - {% endif %} -
    +
    + +
    +
    {% if field.errors %}
    {{ field.errors }}
    {% endif %} +
    +
    + {{ field }} +
    +
    {% else %} {{ field }} {% endif %} -
  • {% endfor %} -
  • +
  • - {% icon name="cog" wrapped=1 %} Back to {{ flag.name }} + Cancel
diff --git a/wagtailflags/templates/wagtailflags/flags/flag_index.html b/wagtailflags/templates/wagtailflags/flags/flag_index.html index 1db7a6c..97235c8 100644 --- a/wagtailflags/templates/wagtailflags/flags/flag_index.html +++ b/wagtailflags/templates/wagtailflags/flags/flag_index.html @@ -1,9 +1,9 @@ {% extends "wagtailadmin/base.html" %} -{% load i18n %} -{% block titletag %}{% trans "Flags" %}: {{ flag.name }}{% endblock %} +{% load i18n wagtailflags_admin %} {% block content %} - {% include "wagtailflags/includes/header.html" with title=flag.name icon="tag" %} + {% include "wagtailflags/includes/flag_breadcrumbs.html" with title=flag.name %} + {% include "wagtailflags/includes/flag_header.html" with title=flag.name icon="flag" %}
diff --git a/wagtailflags/templates/wagtailflags/includes/flag_breadcrumbs.html b/wagtailflags/templates/wagtailflags/includes/flag_breadcrumbs.html new file mode 100644 index 0000000..5d6fd74 --- /dev/null +++ b/wagtailflags/templates/wagtailflags/includes/flag_breadcrumbs.html @@ -0,0 +1,46 @@ +{% extends 'wagtailadmin/shared/headers/slim_header.html' %} +{% load i18n wagtailadmin_tags wagtailflags_admin %} + +{% comment %} +It doesn't seem possible to use the `wagtailadmin/shared/breadcrumbs.html` template for non-page-based breadcrumbs. + +This implementation borrows heavily from `wagtailsnippets/snippets/headers/_base_header.html`, where the same style breadcrumbs are also re-implemented. +{% endcomment %} + +{% block header_content %} + {% with breadcrumb_link_classes='w-flex w-items-center w-h-full w-text-primary w-no-underline w-outline-offset-inside hover:w-underline hover:w-text-primary w-h-full' breadcrumb_item_classes='w-h-full w-flex w-items-center w-overflow-hidden w-transition w-duration-300 w-whitespace-nowrap w-flex-shrink-0 w-font-bold w-text-14' icon_classes='w-w-4 w-h-4 w-ml-3' %} +
+ + +
+ +
+
+ {% endwith %} +{% endblock %} diff --git a/wagtailflags/templates/wagtailflags/includes/flag_header.html b/wagtailflags/templates/wagtailflags/includes/flag_header.html new file mode 100644 index 0000000..f6db9e4 --- /dev/null +++ b/wagtailflags/templates/wagtailflags/includes/flag_header.html @@ -0,0 +1,12 @@ +{% extends 'wagtailadmin/shared/header.html' %} +{% load i18n wagtailadmin_tags wagtailflags_admin %} + +{% block right_column%} + {% if flag|deletable %} + {% url 'wagtailflags:delete_flag' flag.name as delete_link %} + + + {% endif %} +{% endblock %} diff --git a/wagtailflags/templates/wagtailflags/includes/header.html b/wagtailflags/templates/wagtailflags/includes/header.html index 1816c29..3106cc4 100644 --- a/wagtailflags/templates/wagtailflags/includes/header.html +++ b/wagtailflags/templates/wagtailflags/includes/header.html @@ -1,18 +1,9 @@ -{% load wagtailadmin_tags wagtailflags_admin %} +{% extends 'wagtailadmin/shared/header.html' %} +{% load i18n modeladmin_tags wagtailadmin_tags wagtailflags_admin %} -{% if flag %} - - - {% if flag|deletable %} - {% url 'wagtailflags:delete_flag' flag.name as delete_link %} - {% include "wagtailadmin/shared/header.html" with title=title action_icon="bin" action_text='Delete flag' action_url=delete_link %} - {% else %} - {% include "wagtailadmin/shared/header.html" with title=title icon=icon %} - {% endif %} -{% else %} +{% block right_column %} {% url 'wagtailflags:create_flag' as add_link %} {% include "wagtailadmin/shared/header.html" with title=title action_icon=icon action_text='Add flag' action_url=add_link %} -{% endif %} + + {% include 'modeladmin/includes/button.html' with button=view.get_add_button_with_parent %} +{% endblock %} diff --git a/wagtailflags/templates/wagtailflags/index.html b/wagtailflags/templates/wagtailflags/index.html index 0d69c46..edefc28 100644 --- a/wagtailflags/templates/wagtailflags/index.html +++ b/wagtailflags/templates/wagtailflags/index.html @@ -6,8 +6,8 @@ {% block content %} {% trans "Flags" as flags_str %} {% trans "Add a flag" as add_a_flag_str %} - - {% include "wagtailflags/includes/header.html" with title=flags_str icon="tag" %} + {% url 'wagtailflags:create_flag' as add_link %} + {% include "wagtailadmin/shared/header.html" with title=flags_str action_icon=icon action_text=add_a_flag_str action_url=add_link icon="flag" %}
{% if flags|length == 0 %} diff --git a/wagtailflags/views.py b/wagtailflags/views.py index 407ec72..a82c46f 100644 --- a/wagtailflags/views.py +++ b/wagtailflags/views.py @@ -110,8 +110,10 @@ def edit_condition(request, name, condition_pk=None): try: condition = FlagState.objects.get(pk=condition_pk) + title_str = f"Edit {condition} condition" except FlagState.DoesNotExist: condition = None + title_str = f"Create a condition on {flag.name}" if request.method == "POST": form = FlagStateForm( @@ -129,6 +131,7 @@ def edit_condition(request, name, condition_pk=None): "form": form, "condition_str": str(condition), "condition_pk": condition_pk, + "title": title_str, } return render(request, "wagtailflags/flags/edit_condition.html", context) From aeb9ac12b6f4dcf63c7ca98b5f6c48fa973187e3 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Tue, 7 Mar 2023 08:38:18 -0500 Subject: [PATCH 09/12] Fix title tags Co-authored-by: Andy Chosak --- wagtailflags/templates/wagtailflags/flags/edit_condition.html | 4 ++-- wagtailflags/templates/wagtailflags/flags/flag_index.html | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wagtailflags/templates/wagtailflags/flags/edit_condition.html b/wagtailflags/templates/wagtailflags/flags/edit_condition.html index a6a1e4a..fc83167 100644 --- a/wagtailflags/templates/wagtailflags/flags/edit_condition.html +++ b/wagtailflags/templates/wagtailflags/flags/edit_condition.html @@ -1,10 +1,10 @@ {% extends "wagtailadmin/base.html" %} {% load i18n feature_flags wagtailadmin_tags %} -{% block titletag %}{{ title }}{% endblock %} +{% block titletag %}{{ flag.name }}{% endblock %} {% block content %} - {% include "wagtailadmin/shared/header.html" with title=title icon="flag" %} + {% include "wagtailadmin/shared/header.html" with title=flag.name icon="flag" %} {% if condition_pk %}
diff --git a/wagtailflags/templates/wagtailflags/flags/flag_index.html b/wagtailflags/templates/wagtailflags/flags/flag_index.html index 97235c8..88b007b 100644 --- a/wagtailflags/templates/wagtailflags/flags/flag_index.html +++ b/wagtailflags/templates/wagtailflags/flags/flag_index.html @@ -1,6 +1,8 @@ {% extends "wagtailadmin/base.html" %} {% load i18n wagtailflags_admin %} +{% block titletag %}{{ flag.name }}{% endblock %} + {% block content %} {% include "wagtailflags/includes/flag_breadcrumbs.html" with title=flag.name %} {% include "wagtailflags/includes/flag_header.html" with title=flag.name icon="flag" %} From 684ee6857d85a03041d2e8b0a7fc8a695d40c852 Mon Sep 17 00:00:00 2001 From: Will Barton Date: Tue, 7 Mar 2023 08:41:10 -0500 Subject: [PATCH 10/12] =?UTF-8?q?Use=20Wagtail=E2=80=99s=20panel.html=20te?= =?UTF-8?q?mplate=20for=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wagtailflags/flags/create_flag.html | 23 +------------- .../wagtailflags/flags/edit_condition.html | 31 ++----------------- 2 files changed, 4 insertions(+), 50 deletions(-) diff --git a/wagtailflags/templates/wagtailflags/flags/create_flag.html b/wagtailflags/templates/wagtailflags/flags/create_flag.html index 5012174..daf932e 100644 --- a/wagtailflags/templates/wagtailflags/flags/create_flag.html +++ b/wagtailflags/templates/wagtailflags/flags/create_flag.html @@ -10,29 +10,8 @@ {% csrf_token %}