mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 22:52:26 +00:00
Add autocomplete on switchs/ap edit/creation forms
This commit is contained in:
parent
d0a3dda7e4
commit
ed487c3d67
4 changed files with 34 additions and 2 deletions
|
@ -171,7 +171,7 @@ class AddAccessPointForm(NewMachineForm):
|
|||
class EditAccessPointForm(EditMachineForm):
|
||||
"""Form used to edit access points."""
|
||||
|
||||
class Meta:
|
||||
class Meta(EditMachineForm.Meta):
|
||||
model = AccessPoint
|
||||
fields = "__all__"
|
||||
|
||||
|
@ -179,9 +179,17 @@ class EditAccessPointForm(EditMachineForm):
|
|||
class EditSwitchForm(EditMachineForm):
|
||||
"""Form used to edit switches."""
|
||||
|
||||
class Meta:
|
||||
class Meta(EditMachineForm.Meta):
|
||||
model = Switch
|
||||
fields = "__all__"
|
||||
widgets = {
|
||||
"switchbay": AutocompleteModelMixin(
|
||||
url="/topologie/switchbay-autocomplete",
|
||||
),
|
||||
"user": AutocompleteModelMixin(
|
||||
url="/users/user-autocomplete",
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class NewSwitchForm(NewMachineForm):
|
||||
|
|
|
@ -31,9 +31,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% block content %}
|
||||
{% if topoform %}
|
||||
{% bootstrap_form_errors topoform %}
|
||||
{{ topoform.media }}
|
||||
{% endif %}
|
||||
{% if machineform %}
|
||||
{% bootstrap_form_errors machineform %}
|
||||
{{ machineform.media }}
|
||||
{% endif %}
|
||||
{% if domainform %}
|
||||
{% bootstrap_form_errors domainform %}
|
||||
|
|
|
@ -177,4 +177,5 @@ urlpatterns = [
|
|||
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'^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,
|
||||
PortProfile,
|
||||
Port,
|
||||
SwitchBay,
|
||||
)
|
||||
|
||||
from re2o.mixins import AutocompleteViewMixin
|
||||
|
@ -128,6 +129,26 @@ class PortAutocomplete(AutocompleteViewMixin):
|
|||
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):
|
||||
obj_type = PortProfile
|
||||
|
|
Loading…
Reference in a new issue