#7 New forms WIP
* adds new collapsible styled form for new main data * adds/updates translations
This commit is contained in:
+75
-45
@@ -14,6 +14,9 @@ from django.db import transaction
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_PROCESS_TYPE_ID, CODELIST_LAW_ID, \
|
||||
CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from compensation.models import EcoAccountDeduction, EcoAccount
|
||||
from intervention.models import Intervention, Revocation, RevocationDocument
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
@@ -30,51 +33,93 @@ class NewInterventionForm(BaseForm):
|
||||
label=_("Identifier"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Generated automatically if none was given"),
|
||||
required=False,
|
||||
help_text=_("Generated automatically"),
|
||||
)
|
||||
title = forms.CharField(
|
||||
label=_("Title"),
|
||||
label_suffix="",
|
||||
help_text=_("An explanatory name"),
|
||||
max_length=255,
|
||||
)
|
||||
type = forms.CharField(
|
||||
label=_("Type"),
|
||||
type = forms.ModelChoiceField(
|
||||
label=_("Process type"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Which intervention type is this"),
|
||||
required=False,
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_PROCESS_TYPE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-process-type-autocomplete",
|
||||
attrs={
|
||||
}
|
||||
),
|
||||
)
|
||||
law = forms.CharField(
|
||||
laws = forms.ModelMultipleChoiceField(
|
||||
label=_("Law"),
|
||||
label_suffix="",
|
||||
help_text=_("Multiple selection possible"),
|
||||
required=False,
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_LAW_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="codes-law-autocomplete",
|
||||
attrs={
|
||||
}
|
||||
),
|
||||
)
|
||||
registration_office = forms.ModelChoiceField(
|
||||
label=_("Registration office"),
|
||||
label_suffix="",
|
||||
required=False,
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_REGISTRATION_OFFICE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-registration-office-autocomplete",
|
||||
attrs={
|
||||
}
|
||||
),
|
||||
)
|
||||
conservation_office = forms.ModelChoiceField(
|
||||
label=_("Conservation office"),
|
||||
label_suffix="",
|
||||
required=False,
|
||||
queryset=KonovaCode.objects.filter(
|
||||
is_archived=False,
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_CONSERVATION_OFFICE_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="codes-conservation-office-autocomplete",
|
||||
attrs={
|
||||
}
|
||||
),
|
||||
)
|
||||
registration_office_file_number = forms.CharField(
|
||||
label=_("Registration office file number"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Based on which law"),
|
||||
required=False,
|
||||
)
|
||||
conservation_office_file_number = forms.CharField(
|
||||
label=_("Conservation office file number"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
required=False,
|
||||
)
|
||||
handler = forms.CharField(
|
||||
label=_("Intervention handler"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Who performs the intervention"),
|
||||
)
|
||||
data_provider = forms.ModelChoiceField(
|
||||
label=_("Data provider"),
|
||||
label_suffix="",
|
||||
help_text=_("Who provides the data for the intervention"),
|
||||
queryset=Organisation.objects.all(),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="other-orgs-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Organization"),
|
||||
"data-minimum-input-length": 3,
|
||||
}
|
||||
),
|
||||
)
|
||||
data_provider_detail = forms.CharField(
|
||||
label=_("Data provider details"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
help_text=_("Further details"),
|
||||
required=False,
|
||||
help_text=_("Who performs the intervention"),
|
||||
)
|
||||
geometry = gis_forms.MultiPolygonField(
|
||||
widget=gis_forms.OSMWidget(
|
||||
@@ -90,16 +135,6 @@ class NewInterventionForm(BaseForm):
|
||||
label_suffix="",
|
||||
help_text=_("Where does the intervention take place")
|
||||
)
|
||||
documents = forms.FileField(
|
||||
widget=forms.ClearableFileInput(
|
||||
attrs={
|
||||
"multiple": True,
|
||||
}
|
||||
),
|
||||
label=_("Files"),
|
||||
label_suffix="",
|
||||
required=False,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -112,12 +147,9 @@ class NewInterventionForm(BaseForm):
|
||||
identifier = self.cleaned_data.get("identifier", None)
|
||||
title = self.cleaned_data.get("title", None)
|
||||
_type = self.cleaned_data.get("type", None)
|
||||
law = self.cleaned_data.get("law", None)
|
||||
laws = self.cleaned_data.get("laws", None)
|
||||
handler = self.cleaned_data.get("handler", None)
|
||||
data_provider = self.cleaned_data.get("data_provider", None)
|
||||
data_provider_detail = self.cleaned_data.get("data_provider_detail", None)
|
||||
geometry = self.cleaned_data.get("geometry", Polygon())
|
||||
documents = self.cleaned_data.get("documents", []) or []
|
||||
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
@@ -127,10 +159,8 @@ class NewInterventionForm(BaseForm):
|
||||
identifier=identifier,
|
||||
title=title,
|
||||
type=_type,
|
||||
law=law,
|
||||
laws=laws,
|
||||
handler=handler,
|
||||
data_provider=data_provider,
|
||||
data_provider_detail=data_provider_detail,
|
||||
geometry=geometry,
|
||||
created=action,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user