Skip to content

Commit

Permalink
Add support for Wagtail-6 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaelle authored Sep 18, 2024
1 parent 8105e84 commit 01ca483
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
django-version: ["4.1", "4.2"]
wagtail-version: ["4.0", "5.0"]
wagtail-version: ["4.0", "5.0", "6.0"]
exclude:
- django-version: "4.2"
wagtail-version: "4.0"
- django-version: "4.0"
wagtail-version: "6.0"
- django-version: "4.1"
wagtail-version: "6.0"
include:
- python-version: "3.11"
django-version: "4.2"
Expand Down
2 changes: 1 addition & 1 deletion example/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# wagtail
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.contrib.modeladmin",
"wagtail_modeladmin",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
Expand Down
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Framework :: Wagtail",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Internet",
Expand All @@ -33,7 +34,8 @@ djangorestframework = ">=3.11.1,<4.0"

# Optional
Pygments = {version = "^2.6", optional = true}
wagtail = {version = ">=4.0,<6.0", optional = true}
wagtail = {version = ">=4.0,<7.0", optional = true}
wagtail_modeladmin = {version = ">=2.0", optional = true}
pytest = {version = "~7.3.1", optional = true}
pytest-django = {version = "~4.5.2", optional = true}
pytest-cov = {version = "~4.0.0", optional = true}
Expand All @@ -51,14 +53,14 @@ mypy = "~1.2.0"

[tool.poetry.extras]
pygments = ["Pygments"]
example = ["Pygments", "wagtail"]
tests = ["Pygments", "wagtail", "pytest", "pytest-django", "pytest-cov"]
docs = ["wagtail", "sphinx", "sphinx-rtd-theme", "sphinx-autobuild", "sphinxcontrib-httpdomain"]
example = ["Pygments", "wagtail", "wagtail_modeladmin"]
tests = ["Pygments", "wagtail", "wagtail_modeladmin", "pytest", "pytest-django", "pytest-cov"]
docs = ["wagtail", "wagtail_modeladmin", "sphinx", "sphinx-rtd-theme", "sphinx-autobuild", "sphinxcontrib-httpdomain"]

[tool.isort]
profile = "black"
known_first_party = ["salesman", "shop"]
known_third_party = ["rest_framework", "wagtail", "pytest"]
known_third_party = ["rest_framework", "wagtail", "wagtail_modeladmin", "pytest"]

[tool.mypy]
exclude = ["example"]
Expand Down
18 changes: 13 additions & 5 deletions salesman/admin/wagtail/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

from django.contrib.auth.models import AbstractBaseUser
from django.utils.translation import gettext_lazy as _
from wagtail.contrib.modeladmin.helpers import (
AdminURLHelper,
ButtonHelper,
PermissionHelper,
)

try:
from wagtail.contrib.modeladmin.helpers import (
AdminURLHelper,
ButtonHelper,
PermissionHelper,
)
except ImportError:
from wagtail_modeladmin.helpers import (
AdminURLHelper,
ButtonHelper,
PermissionHelper,
)


class OrderPermissionHelper(PermissionHelper):
Expand Down
6 changes: 5 additions & 1 deletion salesman/admin/wagtail/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
from wagtail.admin import messages
from wagtail.contrib.modeladmin.views import DeleteView, EditView, IndexView

try:
from wagtail.contrib.modeladmin.views import DeleteView, EditView, IndexView
except ImportError:
from wagtail_modeladmin.views import DeleteView, EditView, IndexView


class OrderIndexView(IndexView):
Expand Down
6 changes: 5 additions & 1 deletion salesman/admin/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from typing import Type

from wagtail.admin.panels import ObjectList, Panel
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register

try:
from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
except ImportError:
from wagtail_modeladmin.options import ModelAdmin, modeladmin_register

from salesman.conf import app_settings
from salesman.core.utils import get_salesman_model
Expand Down
7 changes: 6 additions & 1 deletion salesman/orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ def get_wagtail_admin_attribute(cls, name: str) -> Any | None:
if (
"salesman.admin" in settings.INSTALLED_APPS
and "wagtail.admin" in settings.INSTALLED_APPS
and "wagtail.contrib.modeladmin" in settings.INSTALLED_APPS
and any(
[
"wagtail.contrib.modeladmin" in settings.INSTALLED_APPS,
"wagtail_modeladmin" in settings.INSTALLED_APPS,
]
)
):
from salesman.admin.wagtail.mixins import WagtailOrderAdminMixin

Expand Down

0 comments on commit 01ca483

Please sign in to comment.