Incorporate PermissionedForm into WagtailAdminModelForm

pull/8153/head
Matt Westcott 2022-03-01 13:50:23 +00:00
rodzic bbd3c22f30
commit cb52b95e76
2 zmienionych plików z 19 dodań i 3 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ except ImportError:
install_requires = [
"Django>=3.2,<4.1",
"django-modelcluster>=6.0,<7.0",
"django-permissionedforms>=0.1,<1.0",
"django-taggit>=2.0,<3.0",
"django-treebeard>=4.5.1,<5.0",
"djangorestframework>=3.11.1,<4.0",

Wyświetl plik

@ -2,7 +2,12 @@ import copy
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from modelcluster.forms import ClusterForm, ClusterFormMetaclass
from modelcluster.forms import ClusterForm, ClusterFormMetaclass, ClusterFormOptions
from permissionedforms import (
PermissionedForm,
PermissionedFormMetaclass,
PermissionedFormOptionsMixin,
)
from taggit.managers import TaggableManager
from wagtail.admin import widgets
@ -86,7 +91,15 @@ def formfield_for_dbfield(db_field, **kwargs):
return db_field.formfield(**kwargs)
class WagtailAdminModelFormMetaclass(ClusterFormMetaclass):
class WagtailAdminModelFormOptions(PermissionedFormOptionsMixin, ClusterFormOptions):
# Container for the options set in the inner 'class Meta' of a model form, supporting
# extensions for both ClusterForm ('formsets') and PermissionedForm ('field_permissions').
pass
class WagtailAdminModelFormMetaclass(PermissionedFormMetaclass, ClusterFormMetaclass):
options_class = WagtailAdminModelFormOptions
# Override the behaviour of the regular ModelForm metaclass -
# which handles the translation of model fields to form fields -
# to use our own formfield_for_dbfield function to do that translation.
@ -112,7 +125,9 @@ class WagtailAdminModelFormMetaclass(ClusterFormMetaclass):
return WagtailAdminModelForm
class WagtailAdminModelForm(ClusterForm, metaclass=WagtailAdminModelFormMetaclass):
class WagtailAdminModelForm(
PermissionedForm, ClusterForm, metaclass=WagtailAdminModelFormMetaclass
):
pass