auth_saml: move role choice field outside of module (#53442)
This commit is contained in:
parent
ad2d35fed5
commit
b524ae206f
|
@ -19,11 +19,12 @@ import warnings
|
|||
|
||||
import PIL.Image
|
||||
from django.core.files import File
|
||||
from django.forms import CharField, EmailField, FileField, ValidationError
|
||||
from django.forms import CharField, EmailField, FileField, ModelChoiceField, ValidationError
|
||||
from django.forms.fields import FILE_INPUT_CONTRADICTION
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from authentic2 import app_settings
|
||||
from authentic2.a2_rbac.models import Role
|
||||
from authentic2.forms.widgets import (
|
||||
CheckPasswordInput,
|
||||
EmailInput,
|
||||
|
@ -31,6 +32,7 @@ from authentic2.forms.widgets import (
|
|||
PasswordInput,
|
||||
ProfileImageInput,
|
||||
)
|
||||
from authentic2.manager.utils import label_from_role
|
||||
from authentic2.passwords import validate_password
|
||||
from authentic2.validators import email_validator
|
||||
|
||||
|
@ -115,3 +117,12 @@ class ProfileImageField(FileField):
|
|||
class ValidatedEmailField(EmailField):
|
||||
default_validators = [email_validator]
|
||||
widget = EmailInput
|
||||
|
||||
|
||||
class RoleChoiceField(ModelChoiceField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.queryset = Role.objects.exclude(slug__startswith='_')
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
return label_from_role(obj)
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
|
||||
from django import forms
|
||||
|
||||
from authentic2.a2_rbac.models import Role
|
||||
from authentic2.forms.fields import RoleChoiceField
|
||||
from authentic2.forms.widgets import SelectAttributeWidget
|
||||
from authentic2.manager.utils import label_from_role
|
||||
|
||||
from .models import SAMLAuthenticator
|
||||
|
||||
|
@ -59,15 +58,6 @@ class SAMLAuthenticatorAdvancedForm(forms.ModelForm):
|
|||
del self.fields['metadata_http_timeout']
|
||||
|
||||
|
||||
class RoleChoiceField(forms.ModelChoiceField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.queryset = Role.objects.exclude(slug__startswith='_')
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
return label_from_role(obj)
|
||||
|
||||
|
||||
class SAMLRelatedObjectForm(forms.ModelForm):
|
||||
class Meta:
|
||||
exclude = ('authenticator',)
|
||||
|
|
Loading…
Reference in New Issue