mpeltriaux
d785285805
* refactors konova/autocompletes.py by splitting into individual files and moving them to fitting apps * autocomplete files now live in APPNAME/autocomplete/...
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
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 django.db.models import Q
|
|
|
|
from intervention.models import Intervention
|
|
|
|
|
|
class InterventionAutocomplete(Select2QuerySetView):
|
|
""" Autocomplete for intervention entries
|
|
|
|
Only returns entries that are accessible for the requesting user
|
|
|
|
"""
|
|
def get_queryset(self):
|
|
user = self.request.user
|
|
if user.is_anonymous:
|
|
return Intervention.objects.none()
|
|
qs = Intervention.objects.filter(
|
|
Q(deleted=None) &
|
|
Q(users__in=[user]) |
|
|
Q(teams__in=user.teams.all())
|
|
).order_by(
|
|
"identifier"
|
|
).distinct()
|
|
if self.q:
|
|
qs = qs.filter(
|
|
Q(identifier__icontains=self.q) |
|
|
Q(title__icontains=self.q)
|
|
).distinct()
|
|
return qs
|