forked from DGNum/gestioCOF
40 lines
1.1 KiB
Python
40 lines
1.1 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 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__is_cof=True)
|
|
return qset_filter
|
|
|
|
def result_uuid(self, user):
|
|
return user.username
|
|
|
|
|
|
class COFOthersSearch(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__is_cof=False)
|
|
return qset_filter
|
|
|
|
def result_uuid(self, user):
|
|
return user.username
|
|
|
|
|
|
class COFSearch(autocomplete.Compose):
|
|
search_units = [
|
|
("members", COFMemberSearch()),
|
|
("others", COFOthersSearch()),
|
|
("clippers", autocomplete.LDAPSearch()),
|
|
]
|