auth_saml: move model form parameters to class (#53442)

This commit is contained in:
Valentin Deniaud 2022-09-20 11:51:05 +02:00
parent fc093735ba
commit c12438b5ee
2 changed files with 10 additions and 8 deletions

View File

@ -17,6 +17,7 @@
from django import forms
from authentic2.a2_rbac.models import Role
from authentic2.forms.widgets import SelectAttributeWidget
from authentic2.manager.utils import label_from_role
from .models import SAMLAuthenticator
@ -65,3 +66,10 @@ class RoleChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return label_from_role(obj)
class SAMLRelatedObjectForm(forms.ModelForm):
class Meta:
exclude = ('authenticator',)
field_classes = {'role': RoleChoiceField}
widgets = {'user_field': SelectAttributeWidget}

View File

@ -7,11 +7,10 @@ from django.urls import reverse
from django.views.generic import CreateView, DeleteView, UpdateView
from mellon.utils import get_idp
from authentic2.forms.widgets import SelectAttributeWidget
from authentic2.manager.views import MediaMixin, TitleMixin
from authentic2.utils.misc import redirect_to_login
from .forms import RoleChoiceField
from .forms import SAMLRelatedObjectForm
from .models import AddRoleAction, SAMLAttributeLookup, SAMLAuthenticator, SetAttributeAction
@ -60,12 +59,7 @@ class SAMLAuthenticatorMixin(MediaMixin, TitleMixin):
return super().dispatch(request, *args, **kwargs)
def get_form_class(self):
return modelform_factory(
self.model,
exclude=('authenticator',),
field_classes={'role': RoleChoiceField},
widgets={'user_field': SelectAttributeWidget},
)
return modelform_factory(self.model, SAMLRelatedObjectForm)
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()