gestioCOF/bds/autocomplete.py

44 lines
1.1 KiB
Python
Raw Normal View History

2020-06-05 17:02:16 +02:00
from django.contrib.auth import get_user_model
from django.db.models import Q
from shared import autocomplete
2020-06-05 17:02:16 +02:00
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
def result_uuid(self, user):
return user.username
2020-06-05 17:02:16 +02:00
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
def result_uuid(self, user):
return user.username
2020-06-05 17:02:16 +02:00
class BDSSearch(autocomplete.Compose):
search_units = [
("members", BDSMemberSearch()),
("others", BDSOthersSearch()),
("clippers", autocomplete.LDAPSearch()),
2020-06-05 17:02:16 +02:00
]
bds_search = BDSSearch()