Konova code improvements

* improves rendering of codes as string (short names will be used if existing)
* reduces selectable konova codes to leafs (as discussed with experts)
* automatically resizes the width of modal form fields to w-100
* adds/updates translations
This commit is contained in:
mipel
2021-08-24 14:50:51 +02:00
parent 06d74f8ccb
commit 9b2aaaa5fa
7 changed files with 126 additions and 95 deletions

View File

@@ -13,8 +13,10 @@ from django.db import transaction
from django.http import HttpRequest, HttpResponseRedirect
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy as _con
from codelist.models import KonovaCode
from codelist.settings import CODELIST_BIOTOPES_ID
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
from konova.contexts import BaseContext
from konova.forms import BaseForm, BaseModalForm
@@ -41,13 +43,14 @@ class NewPaymentForm(BaseModalForm):
amount = forms.DecimalField(
min_value=0.00,
decimal_places=2,
label=_("Amount"),
label=_con("money", "Amount"), # contextual translation
label_suffix=_(""),
help_text=_("Amount in Euro"),
help_text=_("in Euro"),
)
due = forms.DateField(
label=_("Due on"),
label_suffix=_(""),
required=False,
help_text=_("Due on which date"),
widget=forms.DateInput(
attrs={
@@ -104,12 +107,13 @@ class NewStateModalForm(BaseModalForm):
help_text=_("Select the biotope type"),
queryset=KonovaCode.objects.filter(
is_active=True,
is_leaf=True,
code_lists__in=[CODELIST_BIOTOPES_ID],
),
widget=autocomplete.ModelSelect2(
url="codes-biotope-autocomplete",
attrs={
"data-placeholder": _("Biotope Type"),
"data-minimum-input-length": 3,
}
),
)
@@ -280,7 +284,7 @@ class NewActionModalForm(BaseModalForm):
url="codes-compensation-action-autocomplete",
attrs={
"data-placeholder": _("Action"),
"data-minimum-input-length": 3,
"data-class": "w-100",
}
),
)
@@ -312,8 +316,8 @@ class NewActionModalForm(BaseModalForm):
help_text=_("Additional comment, maximum {} letters").format(200),
widget=forms.Textarea(
attrs={
"cols": 30,
"rows": 5,
"class": "w-100"
}
)
)

View File

@@ -11,6 +11,7 @@ from django.core.validators import MinValueValidator
from django.db.models import Sum
from django.utils.translation import gettext_lazy as _
from codelist.models import KonovaCode
from intervention.models import Intervention, ResponsibilityData
from konova.models import BaseObject, BaseResource, Geometry, UuidModel
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
@@ -22,7 +23,7 @@ class Payment(BaseResource):
Holds data on a payment for an intervention (alternative to a classic compensation)
"""
amount = models.FloatField(validators=[MinValueValidator(limit_value=0.00)])
due_on = models.DateField(null=True)
due_on = models.DateField(null=True, blank=True)
comment = models.CharField(
max_length=1000,
null=True,
@@ -42,7 +43,12 @@ class CompensationState(UuidModel):
"""
Compensations must define the state of an area before and after the compensation.
"""
biotope_type = models.CharField(max_length=500, null=True, blank=True)
biotope_type = models.ForeignKey(
KonovaCode,
on_delete=models.SET_NULL,
null=True,
blank=True
)
surface = models.FloatField()
def __str__(self):
@@ -65,7 +71,12 @@ class CompensationAction(BaseResource):
"""
Compensations include actions like planting trees, refreshing rivers and so on.
"""
action_type = models.CharField(max_length=500, null=True, blank=True)
action_type = models.ForeignKey(
KonovaCode,
on_delete=models.SET_NULL,
null=True,
blank=True
)
amount = models.FloatField()
unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices)
comment = models.TextField(blank=True, null=True, help_text="Additional comment")