Autocomplete refactoring
* refactors konova/autocompletes.py by splitting into individual files and moving them to fitting apps
* autocomplete files now live in APPNAME/autocomplete/...
This commit is contained in:
7
intervention/autocomplete/__init__.py
Normal file
7
intervention/autocomplete/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 18.08.22
|
||||
|
||||
"""
|
||||
36
intervention/autocomplete/intervention.py
Normal file
36
intervention/autocomplete/intervention.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
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
|
||||
@@ -60,7 +60,7 @@ class NewInterventionForm(BaseForm):
|
||||
code_lists__in=[CODELIST_PROCESS_TYPE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-process-type-autocomplete",
|
||||
url="codelist:process-type-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class NewInterventionForm(BaseForm):
|
||||
code_lists__in=[CODELIST_LAW_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="codes-law-autocomplete",
|
||||
url="codelist:law-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class NewInterventionForm(BaseForm):
|
||||
code_lists__in=[CODELIST_REGISTRATION_OFFICE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-registration-office-autocomplete",
|
||||
url="codelist:registration-office-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class NewInterventionForm(BaseForm):
|
||||
code_lists__in=[CODELIST_CONSERVATION_OFFICE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-conservation-office-autocomplete",
|
||||
url="codelist:conservation-office-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class NewInterventionForm(BaseForm):
|
||||
code_lists__in=[CODELIST_HANDLER_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-handler-autocomplete",
|
||||
url="codelist:handler-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class NewEcoAccountDeductionModalForm(BaseModalForm):
|
||||
help_text=_("Only recorded accounts can be selected for deductions"),
|
||||
queryset=EcoAccount.objects.filter(deleted=None),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="accounts-autocomplete",
|
||||
url="compensation:acc:autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Eco-account"),
|
||||
"data-minimum-input-length": 3,
|
||||
@@ -60,7 +60,7 @@ class NewEcoAccountDeductionModalForm(BaseModalForm):
|
||||
help_text=_("Only shared interventions can be selected"),
|
||||
queryset=Intervention.objects.filter(deleted=None),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="interventions-autocomplete",
|
||||
url="intervention:autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Intervention"),
|
||||
"data-minimum-input-length": 3,
|
||||
|
||||
@@ -36,7 +36,7 @@ class ShareModalForm(BaseModalForm):
|
||||
required=False,
|
||||
queryset=Team.objects.all(),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="share-team-autocomplete",
|
||||
url="user:share-team-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
"data-minimum-input-length": 3,
|
||||
@@ -50,7 +50,7 @@ class ShareModalForm(BaseModalForm):
|
||||
required=False,
|
||||
queryset=User.objects.all(),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="share-user-autocomplete",
|
||||
url="user:share-user-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
"data-minimum-input-length": 3,
|
||||
|
||||
@@ -7,6 +7,7 @@ Created on: 30.11.20
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from intervention.autocomplete.intervention import InterventionAutocomplete
|
||||
from intervention.views import index_view, new_view, detail_view, edit_view, remove_view, new_document_view, share_view, \
|
||||
create_share_view, remove_revocation_view, new_revocation_view, check_view, log_view, new_deduction_view, \
|
||||
record_view, remove_document_view, get_document_view, get_revocation_view, new_id_view, report_view, \
|
||||
@@ -48,4 +49,7 @@ urlpatterns = [
|
||||
path('<id>/revocation/<revocation_id>/edit', edit_revocation_view, name='edit-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/remove', remove_revocation_view, name='remove-revocation'),
|
||||
path('revocation/<doc_id>', get_revocation_view, name='get-doc-revocation'),
|
||||
|
||||
# Autocomplete
|
||||
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="autocomplete"),
|
||||
]
|
||||
Reference in New Issue
Block a user