#38 User requests

* implements 5) "Add 'Maßnahmentyp' for KOMs "
    * prepares model and form fields as mixins for easy extension to eco accounts and emas (possibly in the future?)
This commit is contained in:
2021-11-15 15:55:09 +01:00
parent e4a40cdff5
commit 9211068dc7
7 changed files with 188 additions and 68 deletions

View File

@@ -115,7 +115,33 @@ class CompensationResponsibleFormMixin(forms.Form):
)
class NewCompensationForm(AbstractCompensationForm):
class CEFCompensationFormMixin(forms.Form):
""" A form mixin, providing CEF compensation field
"""
is_cef = forms.BooleanField(
label_suffix="",
label=_("Is CEF"),
help_text=_("Optionally: Whether this compensation is a CEF compensation?"),
required=False,
widget=forms.CheckboxInput()
)
class CoherenceCompensationFormMixin(forms.Form):
""" A form mixin, providing coherence compensation field
"""
is_coherence_keeping = forms.BooleanField(
label_suffix="",
label=_("Is coherence keeping"),
help_text=_("Optionally: Whether this compensation is a coherence keeping compensation?"),
required=False,
widget=forms.CheckboxInput()
)
class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, CoherenceCompensationFormMixin):
""" Form for creating new compensations.
Can be initialized with an intervention id for preselecting the related intervention.
@@ -146,6 +172,8 @@ class NewCompensationForm(AbstractCompensationForm):
"identifier",
"title",
"intervention",
"is_cef",
"is_coherence_keeping",
"comment",
]
@@ -177,6 +205,8 @@ class NewCompensationForm(AbstractCompensationForm):
identifier = self.cleaned_data.get("identifier", None)
title = self.cleaned_data.get("title", None)
intervention = self.cleaned_data.get("intervention", None)
is_cef = self.cleaned_data.get("is_cef", None)
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
comment = self.cleaned_data.get("comment", None)
# Create log entry
@@ -193,6 +223,8 @@ class NewCompensationForm(AbstractCompensationForm):
title=title,
intervention=intervention,
created=action,
is_cef=is_cef,
is_coherence_keeping=is_coherence_keeping,
geometry=geometry,
comment=comment,
)
@@ -217,6 +249,8 @@ class EditCompensationForm(NewCompensationForm):
"identifier": self.instance.identifier,
"title": self.instance.title,
"intervention": self.instance.intervention,
"is_cef": self.instance.is_cef,
"is_coherence_keeping": self.instance.is_coherence_keeping,
"comment": self.instance.comment,
}
disabled_fields = []
@@ -231,6 +265,8 @@ class EditCompensationForm(NewCompensationForm):
identifier = self.cleaned_data.get("identifier", None)
title = self.cleaned_data.get("title", None)
intervention = self.cleaned_data.get("intervention", None)
is_cef = self.cleaned_data.get("is_cef", None)
is_coherence_keeping = self.cleaned_data.get("is_coherence_keeping", None)
comment = self.cleaned_data.get("comment", None)
# Create log entry
@@ -247,6 +283,8 @@ class EditCompensationForm(NewCompensationForm):
self.instance.title = title
self.instance.intervention = intervention
self.instance.geometry = geometry
self.instance.is_cef = is_cef
self.instance.is_coherence_keeping = is_coherence_keeping
self.instance.comment = comment
self.instance.modified = action
self.instance.save()