1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-19 05:52:21 +00:00
nk20/apps/member/filters.py

34 lines
912 B
Python
Raw Normal View History

2020-02-18 20:30:26 +00:00
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
2019-09-23 10:50:14 +00:00
# SPDX-License-Identifier: GPL-3.0-or-later
2020-02-18 20:14:29 +00:00
from django_filters import FilterSet, CharFilter
2019-09-23 10:50:14 +00:00
from django.contrib.auth.models import User
from django.db.models import CharField
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Submit
class UserFilter(FilterSet):
class Meta:
model = User
2020-02-18 11:31:15 +00:00
fields = ['last_name', 'first_name', 'username', 'profile__section']
filter_overrides = {
CharField: {
'filter_class': CharFilter,
'extra': lambda f: {
'lookup_expr': 'icontains'
2019-09-23 10:50:14 +00:00
}
}
}
2020-02-18 11:31:15 +00:00
2019-09-23 10:50:14 +00:00
class UserFilterFormHelper(FormHelper):
form_method = 'GET'
layout = Layout(
2020-02-18 11:31:15 +00:00
'last_name',
'first_name',
'username',
'profile__section',
Submit('Submit', 'Apply Filter'),
2019-09-23 10:50:14 +00:00
)