From 52514f58d6e74574c9bf37d56fb37b9ca5294c5f Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 17 Feb 2020 01:13:14 +0100 Subject: [PATCH] Show matched aliases in the autocompletion list --- apps/note/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/note/views.py b/apps/note/views.py index 0b56a485..fe888613 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -70,7 +70,7 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView): # self.q est le paramètre de la recherche if self.q: - qs = qs.filter(Q(alias__name__regex=self.q) | Q(alias__normalized_name__regex=Alias.normalize(self.q))) + qs = qs.filter(Q(alias__name__regex=self.q) | Q(alias__normalized_name__regex=Alias.normalize(self.q))).distinct() # Filtrage par type de note (user, club, special) note_type = self.forwarded.get("note_type", None) @@ -87,6 +87,17 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView): return qs + def get_result_label(self, result): + aliases = Alias.objects.filter(Q(name__regex=self.q) | Q(normalized_name__regex=Alias.normalize(self.q))).all() + res = str(result) + if aliases.count() > 1 or (aliases.count() == 1 and aliases.get().name != str(result)): + res += " (alias " + for alias in aliases: + if alias.name != str(result): + res += alias.name + ", " + res = res[:-2] + ")" + return res + class TransactionTemplateCreateView(LoginRequiredMixin,CreateView): """