Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wagtail >= 5.2 #229

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.8
- name: Install build requirements
run: python -m pip install wheel
- name: Build package
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.8', '3.9', '3.10', '3.11']
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
Expand Down
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Unreleased
==========
- Add support for Wagtail 5.2 and 6.x
- Drop support for Wagtail < 5.2
- Update `otp_form` to be compatible with Wagtail 5.2 and 6.x
- Add support for Django 5.0


1.6.9 (2023-12-20)
=================
- Include template for branding logo for wagtail > 5.0
Expand Down
2 changes: 1 addition & 1 deletion sandbox/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django>=3.2
wagtail>=4.1
wagtail>=5.2
django-debug-toolbar==3.2.2
-e .[docs,test]
107 changes: 90 additions & 17 deletions sandbox/sandbox/apps/user/models.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,115 @@
from django.apps import apps
from django.contrib import auth
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import (
AbstractBaseUser, PermissionsMixin, UserManager)
AbstractBaseUser,
BaseUserManager,
PermissionsMixin,
)
from django.core.mail import send_mail
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _


class UserManager(BaseUserManager):
use_in_migrations = True

def _create_user(self, email, password, **extra_fields):
"""
Create and save a user with the given email and password.
"""
email = self.normalize_email(email)
# Lookup the real model class from the global app registry so this
# manager method can be used in migrations. This is fine because
# managers are by definition working on the real model.
GlobalUserModel = apps.get_model(
self.model._meta.app_label, self.model._meta.object_name
)
user = self.model(email=email, **extra_fields)
user.password = make_password(password)
user.save(using=self._db)
return user

def create_user(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", False)
extra_fields.setdefault("is_superuser", False)
return self._create_user(email, password, **extra_fields)

def create_superuser(self, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_superuser", True)

if extra_fields.get("is_staff") is not True:
raise ValueError("Superuser must have is_staff=True.")
if extra_fields.get("is_superuser") is not True:
raise ValueError("Superuser must have is_superuser=True.")

return self._create_user(email, password, **extra_fields)

def with_perm(
self, perm, is_active=True, include_superusers=True, backend=None, obj=None
):
if backend is None:
backends = auth._get_backends(return_tuples=True)
if len(backends) == 1:
backend, _ = backends[0]
else:
raise ValueError(
"You have multiple authentication backends configured and "
"therefore must provide the `backend` argument."
)
elif not isinstance(backend, str):
raise TypeError(
"backend must be a dotted import path string (got %r)." % backend
)
else:
backend = auth.load_backend(backend)
if hasattr(backend, "with_perm"):
return backend.with_perm(
perm,
is_active=is_active,
include_superusers=include_superusers,
obj=obj,
)
return self.none()


class User(AbstractBaseUser, PermissionsMixin):
"""Cusomtized version of the default `AbstractUser` from Django.
"""Cusomtized version of the default `AbstractUser` from Django."""

"""
first_name = models.CharField(_('first name'), max_length=100, blank=True)
last_name = models.CharField(_('last name'), max_length=100, blank=True)
email = models.EmailField(_('email address'), blank=True, unique=True)
first_name = models.CharField(_("first name"), max_length=100, blank=True)
last_name = models.CharField(_("last name"), max_length=100, blank=True)
email = models.EmailField(_("email address"), blank=True, unique=True)
is_staff = models.BooleanField(
_('staff status'), default=False,
help_text=_('Designates whether the user can log into this admin '
'site.'))
_("staff status"),
default=False,
help_text=_("Designates whether the user can log into this admin " "site."),
)
is_active = models.BooleanField(
_('active'), default=True,
help_text=_('Designates whether this user should be treated as '
'active. Unselect this instead of deleting accounts.'))
date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
_("active"),
default=True,
help_text=_(
"Designates whether this user should be treated as "
"active. Unselect this instead of deleting accounts."
),
)
date_joined = models.DateTimeField(_("date joined"), default=timezone.now)

objects = UserManager()

USERNAME_FIELD = 'email'
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []

class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
verbose_name = _("user")
verbose_name_plural = _("users")

def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
full_name = "%s %s" % (self.first_name, self.last_name)
return full_name.strip()

def get_short_name(self):
Expand Down
5 changes: 1 addition & 4 deletions sandbox/sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
'wagtail.search',
'wagtail.admin',
'wagtail',
# 'wagtail_modeladmin', # if Wagtail >=5.1; Don't repeat if it's there already
'wagtail.contrib.modeladmin', # if Wagtail <5.1; Don't repeat if it's there already
'wagtail_modeladmin',
'wagtail.contrib.styleguide',

'modelcluster',
Expand Down Expand Up @@ -130,8 +129,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
10 changes: 5 additions & 5 deletions sandbox/sandbox/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import debug_toolbar
from django.conf import settings
from django.contrib import admin
from django.urls import include, re_path
from django.urls import include, path, re_path

from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

urlpatterns = [
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)),
path('cms/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),
path('', include(wagtail_urls)),
]


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

urlpatterns = [
re_path(r'^__debug__/', include(debug_toolbar.urls)),
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

install_requires = [
"Django>=3.2",
"Wagtail>=4.1",
"Wagtail>=5.2",
"django-otp>=0.8.1",
"six>=1.14.0",
"qrcode>=6.1",
Expand All @@ -25,6 +25,7 @@
"isort==5.9.3",
"flake8-blind-except==0.2.0",
"flake8-debugger==4.0.0",
"wagtail-modeladmin==2.0.0"
]

with open("README.rst") as fh:
Expand Down Expand Up @@ -58,18 +59,18 @@
"Environment :: Web Environment",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Wagtail",
"Framework :: Wagtail :: 2",
"Framework :: Wagtail :: 3",
"Framework :: Wagtail :: 4",
"Framework :: Wagtail :: 5",
"Framework :: Wagtail :: 6",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
zip_safe=False,
)
5 changes: 4 additions & 1 deletion src/wagtail_2fa/templates/wagtail_2fa/device_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ <h2>

{# Users can only add devices to their own account #}
{% if user_id == request.user.id %}
<a href="{% url 'wagtail_2fa_device_new' %}" class="button bicolor icon icon-plus">{% trans 'New device' %}</a>
<a href="{% url 'wagtail_2fa_device_new' %}" class="button bicolor button--icon">
<span class="icon-wrapper"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></span>
{% trans 'New device' %}
</a>
{% endif %}
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions src/wagtail_2fa/templates/wagtail_2fa/legacy/otp_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1>{% block branding_login %}{% trans "Enter your two-factor authentication cod
{% endblock %}
<footer class="form-actions">
{% block submit_buttons %}
<button type="submit" class="button button-longrunning" tabindex="3" data-clicked-text="{% trans 'Signing in…' %}">{% icon name="spinner" %}<em>{% trans 'Sign in' %}</em></button>
<button type="submit" class="button button-longrunning" tabindex="3" data-controller="w-progress" data-action="w-progress#activate" data-w-progress-active-value="{% trans 'Signing in…' %}">{% icon name="spinner" %}<em>{% trans 'Sign in' %}</em></button>
<span style="margin-top:1rem;display:block;">
<a href="{% url 'wagtailadmin_logout' %}" class="button button-secondary" tabindex="4">{% trans 'Sign out' %}</a>
</span>
Expand All @@ -55,7 +55,7 @@ <h1>{% block branding_login %}{% trans "Enter your two-factor authentication cod

{% block branding_logo %}
<div class="login-logo">
<img class="login-logo-img" alt="" src="{% versioned_static 'wagtailadmin/images/icons/wagtail.svg' %}" />
{% include "wagtailadmin/icons/wagtail.svg" %}
</div>
{% endblock %}
</main>
Expand Down
4 changes: 2 additions & 2 deletions src/wagtail_2fa/templates/wagtail_2fa/otp_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ <h1>{% block branding_login %}{% trans "Enter your two-factor authentication cod
<input type="hidden" name="next" value="{{ next|default:home_url }}" />

{% block fields %}
{% field field=form.otp_token %}{% endfield %}
{% formattedfield form.otp_token %}

{% block extra_fields %}
{% for field_name, field in form.extra_fields %}
{% field field=field %}{% endfield %}
{% formattedfield field %}
{% endfor %}
{% endblock extra_fields %}

Expand Down
2 changes: 1 addition & 1 deletion src/wagtail_2fa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

class LoginView(RedirectURLMixin, FormView):

if WAGTAIL_VERSION >= (5, 0):
if WAGTAIL_VERSION >= (6, 0):
template_name = "wagtail_2fa/otp_form.html"
else:
template_name = "wagtail_2fa/legacy/otp_form.html"
Expand Down
Loading