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
compensation/autocomplete/__init__.py
Normal file
7
compensation/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
|
||||
|
||||
"""
|
||||
34
compensation/autocomplete/eco_account.py
Normal file
34
compensation/autocomplete/eco_account.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
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 compensation.models import EcoAccount
|
||||
|
||||
|
||||
class EcoAccountAutocomplete(Select2QuerySetView):
|
||||
""" Autocomplete for ecoAccount entries
|
||||
|
||||
Only returns entries that are already recorded and not deleted
|
||||
|
||||
"""
|
||||
def get_queryset(self):
|
||||
if self.request.user.is_anonymous:
|
||||
return EcoAccount.objects.none()
|
||||
qs = EcoAccount.objects.filter(
|
||||
deleted=None,
|
||||
recorded__isnull=False,
|
||||
).order_by(
|
||||
"identifier"
|
||||
)
|
||||
if self.q:
|
||||
qs = qs.filter(
|
||||
Q(identifier__icontains=self.q) |
|
||||
Q(title__icontains=self.q)
|
||||
).distinct()
|
||||
return qs
|
||||
@@ -88,7 +88,7 @@ class NewCompensationForm(AbstractCompensationForm,
|
||||
deleted=None,
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="interventions-autocomplete",
|
||||
url="intervention:autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
"data-minimum-input-length": 3,
|
||||
|
||||
@@ -27,7 +27,7 @@ class CompensationResponsibleFormMixin(forms.Form):
|
||||
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")
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class CompensationResponsibleFormMixin(forms.Form):
|
||||
code_lists__in=[CODELIST_HANDLER_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-handler-autocomplete",
|
||||
url="codelist:handler-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Click for selection"),
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class NewCompensationActionModalForm(BaseModalForm):
|
||||
code_lists__in=[CODELIST_COMPENSATION_ACTION_DETAIL_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="codes-compensation-action-detail-autocomplete",
|
||||
url="codelist:compensation-action-detail-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Action Type detail"),
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class NewCompensationStateModalForm(BaseModalForm):
|
||||
code_lists__in=[CODELIST_BIOTOPES_EXTRA_CODES_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="codes-biotope-extra-type-autocomplete",
|
||||
url="codelist:biotope-extra-type-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Biotope additional type"),
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ Created on: 24.08.21
|
||||
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
||||
from compensation.views.eco_account import *
|
||||
|
||||
app_name = "acc"
|
||||
@@ -47,4 +49,6 @@ urlpatterns = [
|
||||
path('<id>/deduction/<deduction_id>/edit', deduction_edit_view, name='edit-deduction'),
|
||||
path('<id>/deduct/new', new_deduction_view, name='new-deduction'),
|
||||
|
||||
# Autocomplete
|
||||
path("atcmplt/eco-accounts", EcoAccountAutocomplete.as_view(), name="autocomplete"),
|
||||
]
|
||||
Reference in New Issue
Block a user