mirror of https://gitlab.crans.org/bde/nk20
Display matched alias in user table
This commit is contained in:
parent
0de69cbfaf
commit
cba6a35b6c
|
@ -38,6 +38,8 @@ class UserTable(tables.Table):
|
||||||
"""
|
"""
|
||||||
List all users.
|
List all users.
|
||||||
"""
|
"""
|
||||||
|
alias = tables.Column()
|
||||||
|
|
||||||
section = tables.Column(accessor='profile.section')
|
section = tables.Column(accessor='profile.section')
|
||||||
|
|
||||||
balance = tables.Column(accessor='note.balance', verbose_name=_("Balance"))
|
balance = tables.Column(accessor='note.balance', verbose_name=_("Balance"))
|
||||||
|
@ -50,7 +52,7 @@ class UserTable(tables.Table):
|
||||||
'class': 'table table-condensed table-striped table-hover'
|
'class': 'table table-condensed table-striped table-hover'
|
||||||
}
|
}
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
fields = ('last_name', 'first_name', 'username', 'email')
|
fields = ('last_name', 'first_name', 'username', 'alias', 'email')
|
||||||
model = User
|
model = User
|
||||||
row_attrs = {
|
row_attrs = {
|
||||||
'class': 'table-row',
|
'class': 'table-row',
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.contrib.auth import logout
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.views import LoginView
|
from django.contrib.auth.views import LoginView
|
||||||
from django.db.models import Q
|
from django.db.models import Q, F
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -172,7 +172,9 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
"""
|
"""
|
||||||
Filter the user list with the given pattern.
|
Filter the user list with the given pattern.
|
||||||
"""
|
"""
|
||||||
qs = super().get_queryset().distinct().filter(profile__registration_valid=True)
|
qs = super().get_queryset().distinct("pk").annotate(alias=F("note__alias__name"))\
|
||||||
|
.annotate(normalized_alias=F("note__alias__normalized_name"))\
|
||||||
|
.filter(profile__registration_valid=True)
|
||||||
if "search" in self.request.GET:
|
if "search" in self.request.GET:
|
||||||
pattern = self.request.GET["search"]
|
pattern = self.request.GET["search"]
|
||||||
|
|
||||||
|
@ -184,8 +186,8 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
|
||||||
| Q(last_name__iregex=pattern)
|
| Q(last_name__iregex=pattern)
|
||||||
| Q(profile__section__iregex=pattern)
|
| Q(profile__section__iregex=pattern)
|
||||||
| Q(username__iregex="^" + pattern)
|
| Q(username__iregex="^" + pattern)
|
||||||
| Q(note__alias__name__iregex="^" + pattern)
|
| Q(alias__iregex="^" + pattern)
|
||||||
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
|
| Q(normalized_alias__iregex=Alias.normalize("^" + pattern))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
qs = qs.none()
|
qs = qs.none()
|
||||||
|
|
Loading…
Reference in New Issue