konova/user/autocomplete/team.py
mpeltriaux 157e733c5a Django 4.2
* updates Django to 4.x and other packages (if possible) to latest versions
* Attention: Requires postgresql >= 12.0
* updates code fragments to match requirements of newer package versions
2023-10-12 09:57:05 +02:00

40 lines
971 B
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 18.08.22
"""
from dal_select2.views import Select2QuerySetView
from user.models import User
class TeamAdminAutocomplete(Select2QuerySetView):
""" Autocomplete for share with teams
"""
def get_queryset(self):
if self.request.user.is_anonymous:
return User.objects.none()
qs = User.objects.filter(
id__in=self.forwarded.get("members", [])
).exclude(
id__in=self.forwarded.get("admins", [])
)
if self.q:
qs = qs.filter(
username__icontains=self.q
)
qs = qs.order_by(
"username"
)
return qs
def get_result_label(self, result):
return str(result)
def get_selected_result_label(self, result):
return str(result)