forked from DGNum/gestioCOF
38 lines
1 KiB
Python
38 lines
1 KiB
Python
|
from django.contrib.auth import get_user_model
|
||
|
from django.db.models import Q
|
||
|
|
||
|
from shared.views import autocomplete
|
||
|
|
||
|
User = get_user_model()
|
||
|
|
||
|
|
||
|
class BDSMemberSearch(autocomplete.ModelSearch):
|
||
|
model = User
|
||
|
search_fields = ["username", "first_name", "last_name"]
|
||
|
|
||
|
def get_queryset_filter(self, *args, **kwargs):
|
||
|
qset_filter = super().get_queryset_filter(*args, **kwargs)
|
||
|
qset_filter &= Q(bds__is_member=True)
|
||
|
return qset_filter
|
||
|
|
||
|
|
||
|
class BDSOthersSearch(autocomplete.ModelSearch):
|
||
|
model = User
|
||
|
search_fields = ["username", "first_name", "last_name"]
|
||
|
|
||
|
def get_queryset_filter(self, *args, **kwargs):
|
||
|
qset_filter = super().get_queryset_filter(*args, **kwargs)
|
||
|
qset_filter &= Q(bds__isnull=True) | Q(bds__is_member=False)
|
||
|
return qset_filter
|
||
|
|
||
|
|
||
|
class BDSSearch(autocomplete.Compose):
|
||
|
search_units = [
|
||
|
("members", "username", BDSMemberSearch),
|
||
|
("others", "username", BDSOthersSearch),
|
||
|
("clippers", "clipper", autocomplete.LDAPSearch),
|
||
|
]
|
||
|
|
||
|
|
||
|
bds_search = BDSSearch()
|