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

Fix minor issues with DAL

This commit is contained in:
Jean-Romain Garnier 2021-01-02 00:27:31 +01:00 committed by Gabriel Detraz
parent ce87d7c3de
commit aacb8ef84a
6 changed files with 24 additions and 18 deletions

View file

@ -95,9 +95,11 @@ class IpListAutocomplete(AutocompleteViewMixin):
def filter_results(self):
machine_type = self.forwarded.get("machine_type", None)
self.query_set = self.query_set.filter(interface__isnull=True)
if machine_type:
self.query_set = self.query_set.filter(
ip_type__machinetype__id=machine_type
)
if self.q:
self.query_set = self.query_set.filter(Q(ipv4__startswith=self.q))

View file

@ -270,8 +270,8 @@ class AutocompleteModelMixin(autocomplete.ModelSelect2):
"""
See https://select2.org/configuration/options-api
"""
# By default, only trigger autocompletion after 3 characters have been typed
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# Display the "x" button to clear the input by default
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)
attrs["data-minimum-results-for-search"] = attrs.get(
"data-minimum-results-for-search", 10
@ -294,8 +294,8 @@ class AutocompleteMultipleModelMixin(autocomplete.ModelSelect2Multiple):
"""
See https://select2.org/configuration/options-api
"""
# By default, only trigger autocompletion after 3 characters have been typed
# attrs["data-minimum-input-length"] = attrs.get("data-minimum-input-length", 3)
# Display the "x" button to clear the input by default
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)
attrs["data-minimum-results-for-search"] = attrs.get(
"data-minimum-results-for-search", 10

View file

@ -182,8 +182,8 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
query_filter = "name__icontains" # Override this if necessary
def get_queryset(self):
can, reason, _permission, query_set = self.obj_type.can_list(self.request.user)
if query_set:
self.query_set = query_set
else:
@ -194,4 +194,5 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
else:
if self.q:
self.query_set = self.query_set.filter(**{self.query_filter: self.q})
return self.query_set

View file

@ -39,7 +39,7 @@ See github.com/yourlabs/django-autocomplete-light/issues/1149
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
height: 100% !important;
display: inline !imoortant;
display: inline !important;
overflow-x: hidden !important;
overflow-y: auto !important;
}

View file

@ -44,7 +44,7 @@ class RoomAutocomplete(AutocompleteViewMixin):
# Precision on search to add annotations so search behaves more like users expect it to
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
self.query_set = self.query_set.annotate(
full_name=Concat(
@ -87,7 +87,6 @@ class DormitoryAutocomplete(AutocompleteViewMixin):
class BuildingAutocomplete(AutocompleteViewMixin):
obj_type = Building
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
# We want to be able to filter by dorm so it's easier
self.query_set = self.query_set.annotate(
@ -108,10 +107,9 @@ class SwitchAutocomplete(AutocompleteViewMixin):
class PortAutocomplete(AutocompleteViewMixin):
obj_type = Port
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
# 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(
full_name=Concat(
"switch__name", Value(" "), "port", output_field=CharField()
@ -133,23 +131,29 @@ class PortAutocomplete(AutocompleteViewMixin):
class SwitchBayAutocomplete(AutocompleteViewMixin):
obj_type = SwitchBay
# Precision on search to add annotations so search behaves more like users expect it to
def filter_results(self):
# Comments explain what we try to match
# See RoomAutocomplete.filter_results
self.query_set = self.query_set.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"
),
dorm_full_colon_name=Concat(
"building__dormitory__name",
Value(" : "),
"building__name",
Value(" "),
"name",
),
).all()
if self.q:
@ -157,10 +161,9 @@ class SwitchBayAutocomplete(AutocompleteViewMixin):
Q(full_name__icontains=self.q)
| Q(dorm_name__icontains=self.q)
| Q(dorm_full_name__icontains=self.q)
| Q(dorm_full_colon_name__icontains=self.q)
)
return qs
class PortProfileAutocomplete(AutocompleteViewMixin):
obj_type = PortProfile