#7 New Form
* adds NewEmaForm and EditEmaForm * refactors ResponsibilityData related form fields into reusable mixin CompensationResponsibleFormMixin * used in NewEcoAccountForm and NewEmaForm for easier maintaining and reducing amount of code * refactors templates /xy/new/view.html into /xy/form/view.html since the same template file is used for new and edit forms
This commit is contained in:
@@ -85,10 +85,61 @@ class AbstractCompensationForm(BaseForm):
|
||||
abstract = True
|
||||
|
||||
|
||||
class CompensationResponsibleFormMixin(forms.Form):
|
||||
""" Encapsulates form fields used in different compensation related models like EcoAccount or EMA
|
||||
|
||||
"""
|
||||
conservation_office = forms.ModelChoiceField(
|
||||
label=_("Conservation office"),
|
||||
label_suffix="",
|
||||
help_text=_("Select the responsible office"),
|
||||
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={
|
||||
"data-placeholder": _("Click for selection")
|
||||
}
|
||||
),
|
||||
)
|
||||
conservation_file_number = forms.CharField(
|
||||
label=_("Conservation office file number"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("ETS-123/ABC.456"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
handler = forms.CharField(
|
||||
label=_("Eco-account handler"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
required=False,
|
||||
help_text=_("Who handles the eco-account"),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Company Mustermann"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class NewCompensationForm(AbstractCompensationForm):
|
||||
""" Form for creating new compensations.
|
||||
|
||||
Can be initialized with an intervention id for preselecting the related intervention.
|
||||
form = NewCompensationForm(request.POST or None, intervention_id=intervention_id)
|
||||
...
|
||||
The intervention id will not be resolved into the intervention ORM object but instead will be used to initialize
|
||||
the related form field.
|
||||
|
||||
"""
|
||||
intervention = forms.ModelChoiceField(
|
||||
@@ -172,6 +223,9 @@ class NewCompensationForm(AbstractCompensationForm):
|
||||
|
||||
|
||||
class EditCompensationForm(NewCompensationForm):
|
||||
""" Form for editing compensations
|
||||
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("Edit compensation")
|
||||
@@ -224,48 +278,12 @@ class EditCompensationForm(NewCompensationForm):
|
||||
return self.instance
|
||||
|
||||
|
||||
class NewEcoAccountForm(AbstractCompensationForm):
|
||||
conservation_office = forms.ModelChoiceField(
|
||||
label=_("Conservation office"),
|
||||
label_suffix="",
|
||||
help_text=_("Select the responsible office"),
|
||||
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={
|
||||
"data-placeholder": _("Click for selection")
|
||||
}
|
||||
),
|
||||
)
|
||||
conservation_file_number = forms.CharField(
|
||||
label=_("Conservation office file number"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("ETS-123/ABC.456"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
handler = forms.CharField(
|
||||
label=_("Eco-account handler"),
|
||||
label_suffix="",
|
||||
max_length=255,
|
||||
required=False,
|
||||
help_text=_("Who handles the eco-account"),
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
"placeholder": _("Company Mustermann"),
|
||||
"class": "form-control",
|
||||
}
|
||||
)
|
||||
)
|
||||
class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMixin):
|
||||
""" Form for creating eco accounts
|
||||
|
||||
Inherits from basic AbstractCompensationForm and further form fields from CompensationResponsibleFormMixin
|
||||
|
||||
"""
|
||||
field_order = [
|
||||
"identifier",
|
||||
"title",
|
||||
@@ -333,6 +351,9 @@ class NewEcoAccountForm(AbstractCompensationForm):
|
||||
|
||||
|
||||
class EditEcoAccountForm(NewEcoAccountForm):
|
||||
""" Form for editing eco accounts
|
||||
|
||||
"""
|
||||
surface = forms.DecimalField(
|
||||
min_value=0.00,
|
||||
decimal_places=2,
|
||||
|
||||
Reference in New Issue
Block a user