42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
Created on: 07.12.20
|
|
|
|
"""
|
|
from dal_select2.views import Select2QuerySetView
|
|
|
|
from organisation.enums import OrganisationTypeEnum
|
|
from organisation.models import Organisation
|
|
|
|
|
|
class OrganisationAutocomplete(Select2QuerySetView):
|
|
def get_queryset(self):
|
|
if self.request.user.is_anonymous:
|
|
return Organisation.objects.none()
|
|
qs = Organisation.objects.all()
|
|
if self.q:
|
|
qs = qs.filter(name__icontains=self.q)
|
|
qs = qs.order_by(
|
|
"name"
|
|
)
|
|
return qs
|
|
|
|
|
|
class NonOfficialOrganisationAutocomplete(Select2QuerySetView):
|
|
def get_queryset(self):
|
|
if self.request.user.is_anonymous:
|
|
return Organisation.objects.none()
|
|
qs = Organisation.objects.all()
|
|
if self.q:
|
|
qs = qs.filter(
|
|
name__icontains=self.q,
|
|
)
|
|
qs = qs.exclude(
|
|
type=OrganisationTypeEnum.OFFICIAL.value
|
|
)
|
|
qs = qs.order_by(
|
|
"name"
|
|
)
|
|
return qs |