2020-06-05 17:02:16 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.db.models import Q
|
2020-07-01 22:29:07 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-06-05 17:02:16 +02:00
|
|
|
|
2020-07-04 13:50:19 +02:00
|
|
|
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"]
|
2020-07-01 22:29:07 +02:00
|
|
|
verbose_name = _("Membres du BDS")
|
2020-06-05 17:02:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-07-04 13:06:24 +02:00
|
|
|
def result_uuid(self, user):
|
|
|
|
return user.username
|
|
|
|
|
2020-07-01 22:29:07 +02:00
|
|
|
def result_link(self, user):
|
|
|
|
return "#TODO"
|
|
|
|
|
2020-06-05 17:02:16 +02:00
|
|
|
|
|
|
|
class BDSOthersSearch(autocomplete.ModelSearch):
|
|
|
|
model = User
|
|
|
|
search_fields = ["username", "first_name", "last_name"]
|
2020-07-01 22:29:07 +02:00
|
|
|
verbose_name = _("Non-membres du BDS")
|
2020-06-05 17:02:16 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-07-04 13:06:24 +02:00
|
|
|
def result_uuid(self, user):
|
|
|
|
return user.username
|
|
|
|
|
2020-07-01 22:29:07 +02:00
|
|
|
def result_link(self, user):
|
|
|
|
return "#TODO"
|
|
|
|
|
|
|
|
|
|
|
|
class BDSLDAPSearch(autocomplete.LDAPSearch):
|
|
|
|
def result_link(self, clipper):
|
|
|
|
return "#TODO"
|
|
|
|
|
2020-06-05 17:02:16 +02:00
|
|
|
|
|
|
|
class BDSSearch(autocomplete.Compose):
|
|
|
|
search_units = [
|
2020-07-04 13:06:24 +02:00
|
|
|
("members", BDSMemberSearch()),
|
|
|
|
("others", BDSOthersSearch()),
|
2020-07-01 22:29:07 +02:00
|
|
|
("clippers", BDSLDAPSearch()),
|
2020-06-05 17:02:16 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
bds_search = BDSSearch()
|