8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Add autocomplete on preferences pannel

This commit is contained in:
chirac 2020-12-28 19:46:50 +01:00
parent 188bed9c18
commit 5c0131d760
3 changed files with 23 additions and 7 deletions

View file

@ -29,7 +29,7 @@ from django.forms import ModelForm, Form
from django.db.models import Q from django.db.models import Q
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from re2o.mixins import FormRevMixin from re2o.mixins import FormRevMixin, AutocompleteModelMixin, AutocompleteMultipleModelMixin
from .models import ( from .models import (
OptionalUser, OptionalUser,
OptionalMachine, OptionalMachine,
@ -168,6 +168,11 @@ class EditAssoOptionForm(ModelForm):
class Meta: class Meta:
model = AssoOption model = AssoOption
fields = "__all__" fields = "__all__"
widgets = {
"utilisateur_asso": AutocompleteModelMixin(
url="/users/user-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -254,6 +259,11 @@ class MandateForm(ModelForm):
class Meta: class Meta:
model = Mandate model = Mandate
fields = "__all__" fields = "__all__"
widgets = {
"president": AutocompleteModelMixin(
url="/users/user-autocomplete",
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop("prefix", self.Meta.model.__name__) prefix = kwargs.pop("prefix", self.Meta.model.__name__)
@ -368,7 +378,9 @@ class RadiusKeyForm(FormRevMixin, ModelForm):
"""Form used to add and edit RADIUS keys.""" """Form used to add and edit RADIUS keys."""
members = forms.ModelMultipleChoiceField( members = forms.ModelMultipleChoiceField(
queryset=Switch.objects.all(), required=False queryset=Switch.objects.all(),
required=False,
widget=AutocompleteMultipleModelMixin(url="/topologie/switch-autocomplete"),
) )
class Meta: class Meta:
@ -391,7 +403,11 @@ class RadiusKeyForm(FormRevMixin, ModelForm):
class SwitchManagementCredForm(FormRevMixin, ModelForm): class SwitchManagementCredForm(FormRevMixin, ModelForm):
"""Form used to add and edit switch management credentials.""" """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: class Meta:
model = SwitchManagementCred model = SwitchManagementCred

View file

@ -24,19 +24,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %} {% endcomment %}
{% load bootstrap3 %} {% load bootstrap3 %}
{% load massive_bootstrap_form %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Preferences" %}{% endblock %} {% block title %}{% trans "Preferences" %}{% endblock %}
{% block content %} {% block content %}
{% bootstrap_form_errors options %} {% bootstrap_form_errors options %}
{{ options.media }}
<h3>{% trans "Editing of preferences" %}</h3> <h3>{% trans "Editing of preferences" %}</h3>
<form class="form" method="post" enctype="multipart/form-data"> <form class="form" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{% massive_bootstrap_form options 'utilisateur_asso,automatic_provision_switchs' %} {% bootstrap_form options %}
{% if formset %} {% if formset %}
{{ formset.management_form }} {{ formset.management_form }}
{% for f in formset %} {% for f in formset %}

View file

@ -25,20 +25,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load bootstrap3 %} {% load bootstrap3 %}
{% load i18n %} {% load i18n %}
{% load massive_bootstrap_form %}
{% block title %}{% trans "Preferences" %}{% endblock %} {% block title %}{% trans "Preferences" %}{% endblock %}
{% block content %} {% block content %}
{% if preferenceform %} {% if preferenceform %}
{% bootstrap_form_errors preferenceform %} {% bootstrap_form_errors preferenceform %}
{{ preferenceform.media }}
{% endif %} {% endif %}
<form class="form" method="post" enctype="multipart/form-data"> <form class="form" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{% if preferenceform %} {% if preferenceform %}
{% massive_bootstrap_form preferenceform 'members,president' %} {% bootstrap_form preferenceform %}
{% endif %} {% endif %}
{% bootstrap_button action_name button_type="submit" icon='ok' button_class='btn-success' %} {% bootstrap_button action_name button_type="submit" icon='ok' button_class='btn-success' %}
</form> </form>