forked from DGNum/gestioCOF
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from django.contrib.auth import get_user_model
|
|
from django.db.models import Q
|
|
|
|
from shared import autocomplete
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class KfetAccountSearch(autocomplete.ModelSearch):
|
|
model = User
|
|
search_fields = [
|
|
"username",
|
|
"first_name",
|
|
"last_name",
|
|
"profile__account_kfet__trigramme",
|
|
]
|
|
|
|
def get_queryset_filter(self, *args, **kwargs):
|
|
qset_filter = super().get_queryset_filter(*args, **kwargs)
|
|
qset_filter &= Q(profile__account_kfet__isnull=False)
|
|
return qset_filter
|
|
|
|
def result_uuid(self, user):
|
|
return user.username
|
|
|
|
|
|
class COFMemberSearch(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(profile__account_kfet__isnull=True) & Q(profile__is_cof=True)
|
|
return qset_filter
|
|
|
|
def result_uuid(self, user):
|
|
return user.username
|
|
|
|
|
|
class OthersSearch(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(profile__account_kfet__isnull=True) & Q(profile__is_cof=False)
|
|
return qset_filter
|
|
|
|
def result_uuid(self, user):
|
|
return user.username
|
|
|
|
|
|
class KfetAutocomplete(autocomplete.Compose):
|
|
search_units = [
|
|
("kfet", KfetAccountSearch()),
|
|
("users_cof", COFMemberSearch()),
|
|
("users_notcof", OthersSearch()),
|
|
("clippers", autocomplete.LDAPSearch()),
|
|
]
|