Skip to content

Commit

Permalink
Merge pull request #195 from katdom13/support/wagtail-4-compatibility
Browse files Browse the repository at this point in the history
Wagtail 4
  • Loading branch information
davisnando authored Nov 23, 2022
2 parents d08515d + a522c3c commit b3f9cc7
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install build requirements
Expand Down
68 changes: 31 additions & 37 deletions .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,42 @@ jobs:
strategy:
max-parallel: 4
matrix:
tox_env:
- py37-django32-wagtail215
- py38-django32-wagtail215
- py38-django32-wagtail216
- py38-django40-wagtail216
- py39-django32-wagtail215
- py39-django32-wagtail216
- py39-django40-wagtail216
- py310-django32-wagtail215
- py310-django32-wagtail216
- py310-django40-wagtail216
python: ['3.8', '3.9', '3.10']
django: ['3.2', '4.0']
wagtail: ['2.16', '3.0', '4.0']
include:
- python-version: "3.7"
tox_env: py37-django32-wagtail215
- python-version: "3.8"
tox_env: py38-django32-wagtail215
- python-version: "3.8"
tox_env: py38-django32-wagtail216
- python-version: "3.8"
tox_env: py38-django40-wagtail216
- python-version: "3.9"
tox_env: py39-django32-wagtail215
- python-version: "3.9"
tox_env: py39-django32-wagtail216
- python-version: "3.9"
tox_env: py39-django40-wagtail216
- python-version: "3.10"
tox_env: py310-django32-wagtail215
- python-version: "3.10"
tox_env: py310-django32-wagtail216
- python-version: "3.10"
tox_env: py310-django40-wagtail216

- wagtail: '2.15'
django: '3.2'
python: '3.7'
- wagtail: '2.15'
django: '3.2'
python: '3.8'
- wagtail: '2.15'
django: '3.2'
python: '3.9'
- wagtail: '2.15'
django: '3.2'
python: '3.10'
- wagtail: '4.0'
django: '4.1'
python: '3.8'
- wagtail: '4.0'
django: '4.1'
python: '3.9'
- wagtail: '4.0'
django: '4.1'
python: '3.10'
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip tox
- name: Test with tox
run: |
tox -e ${{ matrix.tox_env }}
tox
env:
TOXENV: python${{ matrix.python }}-django${{ matrix.django }}-wagtail${{ matrix.wagtail }}
1 change: 0 additions & 1 deletion sandbox/sandbox/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion sandbox/sandbox/apps/home/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.db import models
from wagtail.core.models import Page


Expand Down
9 changes: 7 additions & 2 deletions sandbox/sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

from wagtail import VERSION as WAGTAIL_VERSION

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(PROJECT_DIR)

Expand Down Expand Up @@ -44,7 +46,7 @@
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail.core',
'wagtail' if WAGTAIL_VERSION >= (3, 0) else 'wagtail.core',
'wagtail.contrib.modeladmin',
'wagtail.contrib.styleguide',

Expand Down Expand Up @@ -159,7 +161,10 @@

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
BASE_URL = 'http://example.com'
if WAGTAIL_VERSION >= (3, 0):
WAGTAILADMIN_BASE_URL = 'http://example.com'
else:
BASE_URL = 'http://example.com'


INTERNAL_IPS = ['127.0.0.1']
Expand Down
23 changes: 14 additions & 9 deletions sandbox/sandbox/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import debug_toolbar
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.urls import include, re_path
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

import debug_toolbar
if WAGTAIL_VERSION >= (3, 0):
from wagtail import urls as wagtail_urls
else:
from wagtail.core import urls as wagtail_urls

from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^cms/', include(wagtailadmin_urls)),
url(r'^documents/', include(wagtaildocs_urls)),
url(r'', include(wagtail_urls)),
re_path(r'^admin/', admin.site.urls),
re_path(r'^cms/', include(wagtailadmin_urls)),
re_path(r'^documents/', include(wagtaildocs_urls)),
re_path(r'', include(wagtail_urls)),
]


Expand All @@ -24,5 +29,5 @@
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
re_path(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
13 changes: 10 additions & 3 deletions src/wagtail_2fa/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import qrcode
import qrcode.image.svg
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import SuccessURLAllowedHostsMixin

if DJANGO_VERSION >= (4, 1):
from django.contrib.auth.views import RedirectURLMixin
else:
from django.contrib.auth.views import SuccessURLAllowedHostsMixin as RedirectURLMixin

from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.shortcuts import resolve_url
Expand All @@ -12,15 +18,16 @@
from django.utils.http import url_has_allowed_host_and_scheme
from django.views.decorators.cache import never_cache
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic import DeleteView, FormView, ListView, UpdateView, View
from django.views.generic import (
DeleteView, FormView, ListView, UpdateView, View)
from django_otp import login as otp_login
from django_otp.plugins.otp_totp.models import TOTPDevice

from wagtail_2fa import forms, utils
from wagtail_2fa.mixins import OtpRequiredMixin


class LoginView(SuccessURLAllowedHostsMixin, FormView):
class LoginView(RedirectURLMixin, FormView):
template_name = "wagtail_2fa/otp_form.html"
form_class = forms.TokenForm
redirect_field_name = REDIRECT_FIELD_NAME
Expand Down
8 changes: 7 additions & 1 deletion src/wagtail_2fa/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
from django.contrib.auth.models import Permission
from django.urls import path, re_path, reverse
from django.utils.translation import gettext_lazy as _
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin.menu import MenuItem
from wagtail.core import hooks

if WAGTAIL_VERSION >= (3, 0):
from wagtail import hooks
else:
from wagtail.core import hooks

from wagtail.users.widgets import UserListingButton

from wagtail_2fa import views
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from django.conf import settings
from wagtail import VERSION as WAGTAIL_VERSION


def pytest_configure():
Expand Down Expand Up @@ -28,7 +29,7 @@ def pytest_configure():
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.core",
"wagtail" if WAGTAIL_VERSION >= (3, 0) else "wagtail.core",
"wagtail.contrib.modeladmin",
"modelcluster",
"taggit",
Expand Down
3 changes: 2 additions & 1 deletion tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django_otp import login as otp_login
from django_otp.plugins.otp_totp.models import TOTPDevice

from wagtail_2fa.middleware import VerifyUserMiddleware, VerifyUserPermissionsMiddleware
from wagtail_2fa.middleware import (
VerifyUserMiddleware, VerifyUserPermissionsMiddleware)


def test_verified_request(rf, superuser):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from django_otp import DEVICE_ID_SESSION_KEY
from django_otp.plugins.otp_totp.models import TOTPDevice

from wagtail_2fa.views import DeviceDeleteView, DeviceListView, DeviceUpdateView
from wagtail_2fa.views import (
DeviceDeleteView, DeviceListView, DeviceUpdateView)


def test_device_list_view(admin_client, admin_user, django_assert_max_num_queries):
Expand Down
8 changes: 7 additions & 1 deletion tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from django.contrib import admin
from django.urls import include, path
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls

if WAGTAIL_VERSION >= (3, 0):
from wagtail import urls as wagtail_urls
else:
from wagtail.core import urls as wagtail_urls

from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
Expand Down
24 changes: 18 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
[tox]
envlist =
py{37,38,39,310}-django32-wagtail215
py{38,39,310}-django{32,40}-wagtail216
python{3.7,3.8,3.9,3.10}-django{3.2}-wagtail{2.15,2.16,3.0,4.0}
python{3.8,3.9,3.10}-django{4.0}-wagtail{2.16,3.0,4.0}
python{3.8,3.9,3.10}-django{4.1}-wagtail{4.0}

[testenv]
commands = coverage run --parallel -m pytest {posargs} -vvv

basepython =
python3.7: python3.7
python3.8: python3.8
python3.9: python3.9
python3.10: python3.10

deps =
django32: Django>=3.2,<4.0
django40: Django>=4.0,<4.1
wagtail215: wagtail>=2.15,<2.16 # LTS
wagtail216: wagtail>=2.16,<2.17
django3.2: Django>=3.2,<4.0
django4.0: Django>=4.0,<4.1
django4.1: Django>=4.1,<4.2
wagtail2.15: wagtail>=2.15,<2.16 # LTS
wagtail2.16: wagtail>=2.16,<2.17
wagtail3.0: wagtail>=3.0,<3.1
wagtail4.0: wagtail>=4.0,<4.1

extras = test

[testenv:coverage-report]
Expand Down

0 comments on commit b3f9cc7

Please sign in to comment.