forms: move attribute select widget from auth_oidc (#68384)
This commit is contained in:
parent
e26211af52
commit
c9a912086d
|
@ -30,6 +30,7 @@ import uuid
|
|||
|
||||
import django
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.forms.widgets import ClearableFileInput, DateInput, DateTimeInput
|
||||
from django.forms.widgets import EmailInput as BaseEmailInput
|
||||
from django.forms.widgets import PasswordInput as BasePasswordInput
|
||||
|
@ -37,10 +38,12 @@ from django.forms.widgets import TextInput, TimeInput
|
|||
from django.utils.encoding import force_text
|
||||
from django.utils.formats import get_format, get_language
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.text import capfirst
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from gadjo.templatetags.gadjo import xstatic
|
||||
|
||||
from authentic2 import app_settings
|
||||
from authentic2.models import Attribute
|
||||
from authentic2.passwords import get_password_checker
|
||||
|
||||
DATE_FORMAT_JS_PY_MAPPING = {
|
||||
|
@ -375,3 +378,20 @@ class EmailInput(BaseEmailInput):
|
|||
)
|
||||
context['domains_suggested'] = True
|
||||
return context
|
||||
|
||||
|
||||
class SelectAttributeWidget(forms.Select):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.choices = [('', '---------')] + list(self.get_options().items())
|
||||
|
||||
@staticmethod
|
||||
def get_options():
|
||||
choices = {}
|
||||
for name in ('email', 'username', 'first_name', 'last_name'):
|
||||
field = get_user_model()._meta.get_field(name)
|
||||
choices[name] = '%s (%s)' % (capfirst(field.verbose_name), name)
|
||||
for attribute in Attribute.objects.exclude(name__in=choices):
|
||||
choices[attribute.name] = '%s (%s)' % (attribute.label, attribute.name)
|
||||
choices['ou__slug'] = _('Organizational unit slug (ou__slug)')
|
||||
return choices
|
||||
|
|
|
@ -15,12 +15,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django import forms
|
||||
from django.utils.text import capfirst
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from authentic2.custom_user.models import User
|
||||
from authentic2.forms.widgets import DatalistTextInput
|
||||
from authentic2.models import Attribute
|
||||
from authentic2.forms.widgets import DatalistTextInput, SelectAttributeWidget
|
||||
|
||||
from .models import OIDCClaimMapping, OIDCProvider
|
||||
|
||||
|
@ -36,23 +32,6 @@ class OIDCProviderEditForm(forms.ModelForm):
|
|||
self.fields['ou'].empty_label = None
|
||||
|
||||
|
||||
class SelectAttributeWidget(forms.Select):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.choices = [('', '---------')] + list(self.get_options().items())
|
||||
|
||||
@staticmethod
|
||||
def get_options():
|
||||
choices = {}
|
||||
for name in ('email', 'username', 'first_name', 'last_name'):
|
||||
field = User._meta.get_field(name)
|
||||
choices[name] = '%s (%s)' % (capfirst(field.verbose_name), name)
|
||||
for attribute in Attribute.objects.exclude(name__in=choices):
|
||||
choices[attribute.name] = '%s (%s)' % (attribute.label, attribute.name)
|
||||
choices['ou__slug'] = _('Organizational unit slug (ou__slug)')
|
||||
return choices
|
||||
|
||||
|
||||
class OIDCClaimMappingForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue