mirror of https://gitlab.crans.org/bde/nk20
Show autocompleted aliases instead of note names
This commit is contained in:
parent
52514f58d6
commit
6a4e0de444
|
@ -64,40 +64,40 @@ class NoteAutocomplete(autocomplete.Select2QuerySetView):
|
||||||
"""
|
"""
|
||||||
# Un utilisateur non connecté n'a accès à aucune information
|
# Un utilisateur non connecté n'a accès à aucune information
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
return Note.objects.none()
|
return Alias.objects.none()
|
||||||
|
|
||||||
qs = Note.objects.all()
|
qs = Alias.objects.all()
|
||||||
|
|
||||||
# self.q est le paramètre de la recherche
|
# self.q est le paramètre de la recherche
|
||||||
if self.q:
|
if self.q:
|
||||||
qs = qs.filter(Q(alias__name__regex=self.q) | Q(alias__normalized_name__regex=Alias.normalize(self.q))).distinct()
|
qs = qs.filter(Q(name__regex=self.q) | Q(normalized_name__regex=Alias.normalize(self.q)))\
|
||||||
|
.order_by('normalized_name').distinct()
|
||||||
|
|
||||||
# Filtrage par type de note (user, club, special)
|
# Filtrage par type de note (user, club, special)
|
||||||
note_type = self.forwarded.get("note_type", None)
|
note_type = self.forwarded.get("note_type", None)
|
||||||
if note_type:
|
if note_type:
|
||||||
l = str(note_type).lower()
|
l = str(note_type).lower()
|
||||||
if "user" in l:
|
if "user" in l:
|
||||||
qs = qs.filter(polymorphic_ctype__model="noteuser")
|
qs = qs.filter(note__polymorphic_ctype__model="noteuser")
|
||||||
elif "club" in l:
|
elif "club" in l:
|
||||||
qs = qs.filter(polymorphic_ctype__model="noteclub")
|
qs = qs.filter(note__polymorphic_ctype__model="noteclub")
|
||||||
elif "special" in l:
|
elif "special" in l:
|
||||||
qs = qs.filter(polymorphic_ctype__model="notespecial")
|
qs = qs.filter(note__polymorphic_ctype__model="notespecial")
|
||||||
else:
|
else:
|
||||||
qs = qs.none()
|
qs = qs.none()
|
||||||
|
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
def get_result_label(self, result):
|
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 = result.name
|
||||||
res = str(result)
|
note_name = str(result.note)
|
||||||
if aliases.count() > 1 or (aliases.count() == 1 and aliases.get().name != str(result)):
|
if res != note_name:
|
||||||
res += " (alias "
|
res += " (aka. " + note_name + ")"
|
||||||
for alias in aliases:
|
|
||||||
if alias.name != str(result):
|
|
||||||
res += alias.name + ", "
|
|
||||||
res = res[:-2] + ")"
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def get_result_value(self, result):
|
||||||
|
return str(result.note.pk)
|
||||||
|
|
||||||
|
|
||||||
class TransactionTemplateCreateView(LoginRequiredMixin,CreateView):
|
class TransactionTemplateCreateView(LoginRequiredMixin,CreateView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue