From 5c0131d760bd12bcef259938622602e5db3ed297 Mon Sep 17 00:00:00 2001 From: chirac Date: Mon, 28 Dec 2020 19:46:50 +0100 Subject: [PATCH] Add autocomplete on preferences pannel --- preferences/forms.py | 22 ++++++++++++++++--- .../preferences/edit_preferences.html | 4 ++-- .../templates/preferences/preferences.html | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/preferences/forms.py b/preferences/forms.py index a0880fd6..fdc752ab 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -29,7 +29,7 @@ from django.forms import ModelForm, Form from django.db.models import Q from django import forms from django.utils.translation import ugettext_lazy as _ -from re2o.mixins import FormRevMixin +from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin from .models import ( OptionalUser, OptionalMachine, @@ -168,6 +168,11 @@ class EditAssoOptionForm(ModelForm): class Meta: model = AssoOption fields = "__all__" + widgets = { + "utilisateur_asso": AutocompleteModelMixin( + url="/users/user-autocomplete", + ), + } def __init__(self, *args, **kwargs): prefix = kwargs.pop("prefix", self.Meta.model.__name__) @@ -254,6 +259,11 @@ class MandateForm(ModelForm): class Meta: model = Mandate fields = "__all__" + widgets = { + "president": AutocompleteModelMixin( + url="/users/user-autocomplete", + ), + } def __init__(self, *args, **kwargs): prefix = kwargs.pop("prefix", self.Meta.model.__name__) @@ -368,7 +378,9 @@ class RadiusKeyForm(FormRevMixin, ModelForm): """Form used to add and edit RADIUS keys.""" members = forms.ModelMultipleChoiceField( - queryset=Switch.objects.all(), required=False + queryset=Switch.objects.all(), + required=False, + widget=AutocompleteMultipleModelMixin(url="/topologie/switch-autocomplete"), ) class Meta: @@ -391,7 +403,11 @@ class RadiusKeyForm(FormRevMixin, ModelForm): class SwitchManagementCredForm(FormRevMixin, ModelForm): """Form used to add and edit switch management credentials.""" - members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False) + members = forms.ModelMultipleChoiceField( + Switch.objects.all(), + required=False, + widget=AutocompleteMultipleModelMixin(url="/topologie/switch-autocomplete"), + ) class Meta: model = SwitchManagementCred diff --git a/preferences/templates/preferences/edit_preferences.html b/preferences/templates/preferences/edit_preferences.html index 2d9e1a62..c0fe2256 100644 --- a/preferences/templates/preferences/edit_preferences.html +++ b/preferences/templates/preferences/edit_preferences.html @@ -24,19 +24,19 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endcomment %} {% load bootstrap3 %} -{% load massive_bootstrap_form %} {% load i18n %} {% block title %}{% trans "Preferences" %}{% endblock %} {% block content %} {% bootstrap_form_errors options %} +{{ options.media }}

{% trans "Editing of preferences" %}

{% csrf_token %} - {% massive_bootstrap_form options 'utilisateur_asso,automatic_provision_switchs' %} + {% bootstrap_form options %} {% if formset %} {{ formset.management_form }} {% for f in formset %} diff --git a/preferences/templates/preferences/preferences.html b/preferences/templates/preferences/preferences.html index dda6ddfa..d1409cb8 100644 --- a/preferences/templates/preferences/preferences.html +++ b/preferences/templates/preferences/preferences.html @@ -25,20 +25,20 @@ with this program; if not, write to the Free Software Foundation, Inc., {% load bootstrap3 %} {% load i18n %} -{% load massive_bootstrap_form %} {% block title %}{% trans "Preferences" %}{% endblock %} {% block content %} {% if preferenceform %} {% bootstrap_form_errors preferenceform %} +{{ preferenceform.media }} {% endif %} {% csrf_token %} {% if preferenceform %} - {% massive_bootstrap_form preferenceform 'members,president' %} + {% bootstrap_form preferenceform %} {% endif %} {% bootstrap_button action_name button_type="submit" icon='ok' button_class='btn-success' %}