mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Add autocomplete on switchs/ap edit/creation forms
This commit is contained in:
parent
64ef9109ae
commit
b1fcfc306a
4 changed files with 34 additions and 2 deletions
|
@ -171,7 +171,7 @@ class AddAccessPointForm(NewMachineForm):
|
||||||
class EditAccessPointForm(EditMachineForm):
|
class EditAccessPointForm(EditMachineForm):
|
||||||
"""Form used to edit access points."""
|
"""Form used to edit access points."""
|
||||||
|
|
||||||
class Meta:
|
class Meta(EditMachineForm.Meta):
|
||||||
model = AccessPoint
|
model = AccessPoint
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
||||||
|
@ -179,9 +179,17 @@ class EditAccessPointForm(EditMachineForm):
|
||||||
class EditSwitchForm(EditMachineForm):
|
class EditSwitchForm(EditMachineForm):
|
||||||
"""Form used to edit switches."""
|
"""Form used to edit switches."""
|
||||||
|
|
||||||
class Meta:
|
class Meta(EditMachineForm.Meta):
|
||||||
model = Switch
|
model = Switch
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
widgets = {
|
||||||
|
"switchbay": AutocompleteModelMixin(
|
||||||
|
url="/topologie/switchbay-autocomplete",
|
||||||
|
),
|
||||||
|
"user": AutocompleteModelMixin(
|
||||||
|
url="/users/user-autocomplete",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class NewSwitchForm(NewMachineForm):
|
class NewSwitchForm(NewMachineForm):
|
||||||
|
|
|
@ -31,9 +31,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if topoform %}
|
{% if topoform %}
|
||||||
{% bootstrap_form_errors topoform %}
|
{% bootstrap_form_errors topoform %}
|
||||||
|
{{ topoform.media }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if machineform %}
|
{% if machineform %}
|
||||||
{% bootstrap_form_errors machineform %}
|
{% bootstrap_form_errors machineform %}
|
||||||
|
{{ machineform.media }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if domainform %}
|
{% if domainform %}
|
||||||
{% bootstrap_form_errors domainform %}
|
{% bootstrap_form_errors domainform %}
|
||||||
|
|
|
@ -177,4 +177,5 @@ urlpatterns = [
|
||||||
url(r'^switch-autocomplete/$', views_autocomplete.SwitchAutocomplete.as_view(), name='switch-autocomplete',),
|
url(r'^switch-autocomplete/$', views_autocomplete.SwitchAutocomplete.as_view(), name='switch-autocomplete',),
|
||||||
url(r'^port-autocomplete/$', views_autocomplete.PortAutocomplete.as_view(), name='profile-autocomplete',),
|
url(r'^port-autocomplete/$', views_autocomplete.PortAutocomplete.as_view(), name='profile-autocomplete',),
|
||||||
url(r'^portprofile-autocomplete/$', views_autocomplete.PortProfileAutocomplete.as_view(), name='portprofile-autocomplete',),
|
url(r'^portprofile-autocomplete/$', views_autocomplete.PortProfileAutocomplete.as_view(), name='portprofile-autocomplete',),
|
||||||
|
url(r'^switchbay-autocomplete/$', views_autocomplete.SwitchBayAutocomplete.as_view(), name='switchbay-autocomplete',),
|
||||||
]
|
]
|
||||||
|
|
|
@ -41,6 +41,7 @@ from .models import (
|
||||||
Switch,
|
Switch,
|
||||||
PortProfile,
|
PortProfile,
|
||||||
Port,
|
Port,
|
||||||
|
SwitchBay,
|
||||||
)
|
)
|
||||||
|
|
||||||
from re2o.mixins import AutocompleteViewMixin
|
from re2o.mixins import AutocompleteViewMixin
|
||||||
|
@ -128,6 +129,26 @@ class PortAutocomplete(AutocompleteViewMixin):
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
class SwitchBayAutocomplete(AutocompleteViewMixin):
|
||||||
|
obj_type = SwitchBay
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
# Comments explain what we try to match
|
||||||
|
qs = self.obj_type.objects.annotate(
|
||||||
|
full_name=Concat("building__name", Value(" "), "name"), # Match when the user searches ""
|
||||||
|
dorm_name=Concat("building__dormitory__name", Value(" "), "name"), # Match "Dorm Local Sud"
|
||||||
|
dorm_full_name=Concat("building__dormitory__name", Value(" "), "building__name", Value(" "), "name"), # Match "Dorm J Local Sud"
|
||||||
|
).all()
|
||||||
|
|
||||||
|
if self.q:
|
||||||
|
qs = qs.filter(
|
||||||
|
Q(full_name__icontains=self.q)
|
||||||
|
| Q(dorm_name__icontains=self.q)
|
||||||
|
| Q(dorm_full_name__icontains=self.q)
|
||||||
|
)
|
||||||
|
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class PortProfileAutocomplete(AutocompleteViewMixin):
|
class PortProfileAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = PortProfile
|
obj_type = PortProfile
|
||||||
|
|
Loading…
Reference in a new issue