1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-20 17:41:55 +02:00

Better club search bar

This commit is contained in:
Yohann D'ANELLO
2020-06-21 22:27:32 +02:00
parent b46854e479
commit ac5041f3ec
4 changed files with 51 additions and 41 deletions

View File

@ -24,7 +24,8 @@ class ClubTable(tables.Table):
}
model = Club
template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'name', 'email')
fields = ('name', 'email',)
order_by = ('name',)
row_attrs = {
'class': 'table-row',
'id': lambda record: "row-" + str(record.pk),

View File

@ -299,6 +299,22 @@ class ClubListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
model = Club
table_class = ClubTable
def get_queryset(self, **kwargs):
"""
Filter the user list with the given pattern.
"""
qs = super().get_queryset().filter()
if "search" in self.request.GET:
pattern = self.request.GET["search"]
qs = qs.filter(
Q(name__iregex=pattern)
| Q(note__alias__name__iregex="^" + pattern)
| Q(note__alias__normalized_name__iregex=Alias.normalize("^" + pattern))
)
return qs
class ClubDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
"""