#7 New forms WIP
* adds new collapsible styled form for new main data * adds/updates translations
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
@@ -298,7 +298,7 @@ class Intervention(BaseObject):
|
||||
ret_msgs.append(_("Registration office file number missing"))
|
||||
|
||||
if not self.responsible.conservation_file_number or len(self.responsible.conservation_file_number) == 0:
|
||||
ret_msgs.append(_("Conversation office file number missing"))
|
||||
ret_msgs.append(_("Conservation office file number missing"))
|
||||
except AttributeError:
|
||||
# responsible data not found
|
||||
ret_msgs.append(_("Responsible data missing"))
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<td class="align-middle">{{intervention.responsible.conservation_office.str_as_office|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr {% if not intervention.responsible.conservation_file_number %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
|
||||
<th scope="row">{% trans 'Conversation office file number' %}</th>
|
||||
<th scope="row">{% trans 'Conservation office file number' %}</th>
|
||||
<td class="align-middle">{{intervention.responsible.conservation_file_number|default_if_none:""}}</td>
|
||||
</tr>
|
||||
<tr {% if not intervention.responsible.handler %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
|
||||
|
||||
6
intervention/templates/intervention/new/view.html
Normal file
6
intervention/templates/intervention/new/view.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n l10n %}
|
||||
|
||||
{% block body %}
|
||||
{% include 'form/main_data_collapse_form.html' %}
|
||||
{% endblock %}
|
||||
@@ -58,7 +58,7 @@ def new_view(request: HttpRequest):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "konova/form.html"
|
||||
template = "intervention/new/view.html"
|
||||
form = NewInterventionForm(request.POST or None)
|
||||
if request.method == "POST":
|
||||
if form.is_valid():
|
||||
|
||||
Reference in New Issue
Block a user