mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Fix minor issues with DAL
This commit is contained in:
parent
d1d75209a9
commit
4d37b4506c
6 changed files with 24 additions and 18 deletions
|
@ -95,9 +95,11 @@ class IpListAutocomplete(AutocompleteViewMixin):
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
machine_type = self.forwarded.get("machine_type", None)
|
machine_type = self.forwarded.get("machine_type", None)
|
||||||
self.query_set = self.query_set.filter(interface__isnull=True)
|
self.query_set = self.query_set.filter(interface__isnull=True)
|
||||||
|
|
||||||
if machine_type:
|
if machine_type:
|
||||||
self.query_set = self.query_set.filter(
|
self.query_set = self.query_set.filter(
|
||||||
ip_type__machinetype__id=machine_type
|
ip_type__machinetype__id=machine_type
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.q:
|
if self.q:
|
||||||
self.query_set = self.query_set.filter(Q(ipv4__startswith=self.q))
|
self.query_set = self.query_set.filter(Q(ipv4__startswith=self.q))
|
||||||
|
|
|
@ -270,8 +270,8 @@ class AutocompleteModelMixin(autocomplete.ModelSelect2):
|
||||||
"""
|
"""
|
||||||
See https://select2.org/configuration/options-api
|
See https://select2.org/configuration/options-api
|
||||||
"""
|
"""
|
||||||
# By default, only trigger autocompletion after 3 characters have been typed
|
# Display the "x" button to clear the input by default
|
||||||
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
|
attrs["data-allow-clear"] = attrs.get("data-allow-clear", "true")
|
||||||
# If there are less than 10 results, just show all of them (no need to autocomplete)
|
# If there are less than 10 results, just show all of them (no need to autocomplete)
|
||||||
attrs["data-minimum-results-for-search"] = attrs.get(
|
attrs["data-minimum-results-for-search"] = attrs.get(
|
||||||
"data-minimum-results-for-search", 10
|
"data-minimum-results-for-search", 10
|
||||||
|
@ -294,8 +294,8 @@ class AutocompleteMultipleModelMixin(autocomplete.ModelSelect2Multiple):
|
||||||
"""
|
"""
|
||||||
See https://select2.org/configuration/options-api
|
See https://select2.org/configuration/options-api
|
||||||
"""
|
"""
|
||||||
# By default, only trigger autocompletion after 3 characters have been typed
|
# Display the "x" button to clear the input by default
|
||||||
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
|
attrs["data-allow-clear"] = attrs.get("data-allow-clear", "true")
|
||||||
# If there are less than 10 results, just show all of them (no need to autocomplete)
|
# If there are less than 10 results, just show all of them (no need to autocomplete)
|
||||||
attrs["data-minimum-results-for-search"] = attrs.get(
|
attrs["data-minimum-results-for-search"] = attrs.get(
|
||||||
"data-minimum-results-for-search", 10
|
"data-minimum-results-for-search", 10
|
||||||
|
|
|
@ -182,8 +182,8 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
|
||||||
query_filter = "name__icontains" # Override this if necessary
|
query_filter = "name__icontains" # Override this if necessary
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
||||||
can, reason, _permission, query_set = self.obj_type.can_list(self.request.user)
|
can, reason, _permission, query_set = self.obj_type.can_list(self.request.user)
|
||||||
|
|
||||||
if query_set:
|
if query_set:
|
||||||
self.query_set = query_set
|
self.query_set = query_set
|
||||||
else:
|
else:
|
||||||
|
@ -194,4 +194,5 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
|
||||||
else:
|
else:
|
||||||
if self.q:
|
if self.q:
|
||||||
self.query_set = self.query_set.filter(**{self.query_filter: self.q})
|
self.query_set = self.query_set.filter(**{self.query_filter: self.q})
|
||||||
|
|
||||||
return self.query_set
|
return self.query_set
|
||||||
|
|
|
@ -39,7 +39,7 @@ See github.com/yourlabs/django-autocomplete-light/issues/1149
|
||||||
|
|
||||||
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
|
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
display: inline !imoortant;
|
display: inline !important;
|
||||||
overflow-x: hidden !important;
|
overflow-x: hidden !important;
|
||||||
overflow-y: auto !important;
|
overflow-y: auto !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ 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 }}
|
{{ topoform.media }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if machineform %}
|
{% if machineform %}
|
||||||
{% bootstrap_form_errors machineform %}
|
{% bootstrap_form_errors machineform %}
|
||||||
|
|
|
@ -44,7 +44,7 @@ class RoomAutocomplete(AutocompleteViewMixin):
|
||||||
|
|
||||||
# Precision on search to add annotations so search behaves more like users expect it to
|
# Precision on search to add annotations so search behaves more like users expect it to
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# Suppose we have a dorm named Dorm, a building name B, and rooms from 001 - 999
|
# Suppose we have a dorm named Dorm, a building named B, and rooms from 001 - 999
|
||||||
# Comments explain what we try to match
|
# Comments explain what we try to match
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
full_name=Concat(
|
full_name=Concat(
|
||||||
|
@ -87,7 +87,6 @@ class DormitoryAutocomplete(AutocompleteViewMixin):
|
||||||
class BuildingAutocomplete(AutocompleteViewMixin):
|
class BuildingAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = Building
|
obj_type = Building
|
||||||
|
|
||||||
# Precision on search to add annotations so search behaves more like users expect it to
|
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# We want to be able to filter by dorm so it's easier
|
# We want to be able to filter by dorm so it's easier
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
|
@ -108,10 +107,9 @@ class SwitchAutocomplete(AutocompleteViewMixin):
|
||||||
class PortAutocomplete(AutocompleteViewMixin):
|
class PortAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = Port
|
obj_type = Port
|
||||||
|
|
||||||
# Precision on search to add annotations so search behaves more like users expect it to
|
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# We want to enter the switch name, not just the port number
|
# We want to enter the switch name, not just the port number
|
||||||
# Because we're concatenating a CharField and an Integer, we have to sepcify the output_field
|
# Because we're concatenating a CharField and an Integer, we have to specify the output_field
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
full_name=Concat(
|
full_name=Concat(
|
||||||
"switch__name", Value(" "), "port", output_field=CharField()
|
"switch__name", Value(" "), "port", output_field=CharField()
|
||||||
|
@ -133,23 +131,29 @@ class PortAutocomplete(AutocompleteViewMixin):
|
||||||
class SwitchBayAutocomplete(AutocompleteViewMixin):
|
class SwitchBayAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = SwitchBay
|
obj_type = SwitchBay
|
||||||
|
|
||||||
# Precision on search to add annotations so search behaves more like users expect it to
|
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# Comments explain what we try to match
|
# See RoomAutocomplete.filter_results
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
full_name=Concat(
|
full_name=Concat(
|
||||||
"building__name", Value(" "), "name"
|
"building__name", Value(" "), "name"
|
||||||
), # Match when the user searches ""
|
),
|
||||||
dorm_name=Concat(
|
dorm_name=Concat(
|
||||||
"building__dormitory__name", Value(" "), "name"
|
"building__dormitory__name", Value(" "), "name"
|
||||||
), # Match "Dorm Local Sud"
|
),
|
||||||
dorm_full_name=Concat(
|
dorm_full_name=Concat(
|
||||||
"building__dormitory__name",
|
"building__dormitory__name",
|
||||||
Value(" "),
|
Value(" "),
|
||||||
"building__name",
|
"building__name",
|
||||||
Value(" "),
|
Value(" "),
|
||||||
"name",
|
"name",
|
||||||
), # Match "Dorm J Local Sud"
|
),
|
||||||
|
dorm_full_colon_name=Concat(
|
||||||
|
"building__dormitory__name",
|
||||||
|
Value(" : "),
|
||||||
|
"building__name",
|
||||||
|
Value(" "),
|
||||||
|
"name",
|
||||||
|
),
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
if self.q:
|
if self.q:
|
||||||
|
@ -157,10 +161,9 @@ class SwitchBayAutocomplete(AutocompleteViewMixin):
|
||||||
Q(full_name__icontains=self.q)
|
Q(full_name__icontains=self.q)
|
||||||
| Q(dorm_name__icontains=self.q)
|
| Q(dorm_name__icontains=self.q)
|
||||||
| Q(dorm_full_name__icontains=self.q)
|
| Q(dorm_full_name__icontains=self.q)
|
||||||
|
| Q(dorm_full_colon_name__icontains=self.q)
|
||||||
)
|
)
|
||||||
|
|
||||||
return qs
|
|
||||||
|
|
||||||
|
|
||||||
class PortProfileAutocomplete(AutocompleteViewMixin):
|
class PortProfileAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = PortProfile
|
obj_type = PortProfile
|
||||||
|
|
Loading…
Reference in a new issue