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

@ -40,8 +40,9 @@ class KonovaCode(models.Model):
)
def __str__(self):
if self.is_leaf and self.parent:
return "{} > {}".format(self.parent.long_name, self.long_name)
if self.short_name:
return "{} ({})".format(self.long_name, self.short_name)
else:
return self.long_name

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")

View File

@ -6,6 +6,7 @@ Created on: 07.12.20
"""
from dal_select2.views import Select2QuerySetView
from django.db.models import Q
from codelist.models import KonovaCode
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_ID
@ -92,19 +93,19 @@ class KonovaCodeAutocomplete(Select2QuerySetView):
return KonovaCode.objects.none()
qs = KonovaCode.objects.filter(
is_active=True,
parent__isnull=False,
is_leaf=True,
).order_by(
"long_name"
)
if self.c:
qs = qs.filter(
code_lists__in=[self.c]
)
if self.q:
qs = qs.filter(
long_name__icontains=self.q
)
qs.order_by(
"long_name"
)
q_or = Q()
q_or |= Q(long_name__icontains=self.q)
q_or |= Q(short_name__icontains=self.q)
qs = qs.filter(q_or)
return qs

View File

@ -155,6 +155,16 @@ class BaseModalForm(BaseForm, BSModalForm):
render_submit = True
template = "modal/modal_form.html"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Automatically add bootstrap w-100 class for maximum width of form fields in modals
for key, val in self.fields.items():
val.widget.attrs.update(
{
"class": "w-100"
}
)
def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None):
""" Generic processing of request
@ -249,6 +259,8 @@ class RemoveModalForm(BaseModalForm):
super().__init__(*args, **kwargs)
self.form_title = _("Remove")
self.form_caption = _("Are you sure?")
# Disable automatic w-100 setting for this type of modal form. Looks kinda strange
self.fields["confirm"].widget.attrs["class"] = ""
def save(self):
if isinstance(self.instance, BaseObject):

Binary file not shown.

View File

@ -3,8 +3,8 @@
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#: compensation/filters.py:71 compensation/forms.py:43 compensation/forms.py:48
#: compensation/forms.py:61 compensation/forms.py:219 compensation/forms.py:289
#: compensation/filters.py:71 compensation/forms.py:46 compensation/forms.py:51
#: compensation/forms.py:65 compensation/forms.py:234 compensation/forms.py:314
#: intervention/filters.py:26 intervention/filters.py:40
#: intervention/filters.py:47 intervention/filters.py:48
#: intervention/forms.py:322 intervention/forms.py:334
@ -16,7 +16,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-08-19 14:33+0200\n"
"POT-Creation-Date: 2021-08-24 14:26+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -30,54 +30,54 @@ msgstr ""
msgid "Show only unrecorded"
msgstr "Nur unverzeichnete anzeigen"
#: compensation/forms.py:42 compensation/forms.py:278
#: compensation/forms.py:45 compensation/forms.py:303
#: compensation/templates/compensation/detail/eco_account/includes/withdraws.html:31
#: intervention/templates/intervention/detail/includes/withdraws.html:31
msgid "Amount"
msgstr "Menge"
#: compensation/forms.py:44
msgid "Amount in Euro"
msgstr "Betrag in Euro"
#: compensation/forms.py:47
msgid "in Euro"
msgstr "in Euro"
#: compensation/forms.py:50
#: intervention/templates/intervention/detail/includes/payments.html:31
msgid "Due on"
msgstr "Fällig am"
#: compensation/forms.py:49
#: compensation/forms.py:53
msgid "Due on which date"
msgstr "Zahlung wird an diesem Datum erwartet"
#: compensation/forms.py:62
#: compensation/forms.py:66
msgid "Transfer note"
msgstr "Verwendungszweck"
#: compensation/forms.py:63
#: compensation/forms.py:67
msgid "Note for money transfer"
msgstr "Verwendungszweck für Überweisung"
#: compensation/forms.py:69
#: compensation/forms.py:73
msgid "Payment"
msgstr "Zahlung"
#: compensation/forms.py:70
#: compensation/forms.py:74
msgid "Add a payment for intervention '{}'"
msgstr "Neue Ersatzzahlung zu Eingriff '{}' hinzufügen"
#: compensation/forms.py:82
#: compensation/forms.py:86
msgid "Added payment"
msgstr "Zahlung hinzufügen"
#: compensation/forms.py:99
#: compensation/forms.py:103 compensation/forms.py:115
msgid "Biotope Type"
msgstr "Biotoptyp"
#: compensation/forms.py:102
#: compensation/forms.py:106
msgid "Select the biotope type"
msgstr "Biotoptyp wählen"
#: compensation/forms.py:107
#: compensation/forms.py:122
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:36
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:36
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:36
@ -88,35 +88,35 @@ msgstr "Biotoptyp wählen"
msgid "Surface"
msgstr "Fläche"
#: compensation/forms.py:110 intervention/forms.py:476
#: compensation/forms.py:125 intervention/forms.py:476
msgid "in m²"
msgstr ""
#: compensation/forms.py:115
#: compensation/forms.py:130
msgid "New state"
msgstr "Neuer Zustand"
#: compensation/forms.py:116
#: compensation/forms.py:131
msgid "Insert data for the new state"
msgstr "Geben Sie die Daten des neuen Zustandes ein"
#: compensation/forms.py:124
#: compensation/forms.py:139
msgid "Added state"
msgstr "Zustand hinzugefügt"
#: compensation/forms.py:140 konova/forms.py:158
#: compensation/forms.py:155 konova/forms.py:158
msgid "Object removed"
msgstr "Objekt entfernt"
#: compensation/forms.py:191
#: compensation/forms.py:206
msgid "Deadline Type"
msgstr "Fristart"
#: compensation/forms.py:194
#: compensation/forms.py:209
msgid "Select the deadline type"
msgstr "Fristart wählen"
#: compensation/forms.py:203
#: compensation/forms.py:218
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:31
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:31
#: ema/templates/ema/detail/includes/deadlines.html:31
@ -124,11 +124,11 @@ msgstr "Fristart wählen"
msgid "Date"
msgstr "Datum"
#: compensation/forms.py:206
#: compensation/forms.py:221
msgid "Select date"
msgstr "Datum wählen"
#: compensation/forms.py:218 compensation/forms.py:288
#: compensation/forms.py:233 compensation/forms.py:313
#: compensation/templates/compensation/detail/compensation/includes/actions.html:34
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:34
#: compensation/templates/compensation/detail/compensation/includes/documents.html:31
@ -145,52 +145,78 @@ msgstr "Datum wählen"
msgid "Comment"
msgstr "Kommentar"
#: compensation/forms.py:220 compensation/forms.py:290
#: compensation/forms.py:235 compensation/forms.py:315
#: intervention/forms.py:347 konova/forms.py:305
msgid "Additional comment, maximum {} letters"
msgstr "Zusätzlicher Kommentar, maximal {} Zeichen"
#: compensation/forms.py:231
#: compensation/forms.py:246
msgid "New deadline"
msgstr "Neue Frist"
#: compensation/forms.py:232
#: compensation/forms.py:247
msgid "Insert data for the new deadline"
msgstr "Geben Sie die Daten der neuen Frist ein"
#: compensation/forms.py:249
#: compensation/forms.py:264
msgid "Added deadline"
msgstr "Frist/Termin hinzugefügt"
#: compensation/forms.py:260
#: compensation/forms.py:275
msgid "Action Type"
msgstr "Maßnahmentyp"
#: compensation/forms.py:263
#: compensation/forms.py:278
msgid "Select the action type"
msgstr "Maßnahmentyp wählen"
#: compensation/forms.py:266
#: compensation/forms.py:285
#: compensation/templates/compensation/detail/compensation/includes/actions.html:37
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:37
#: compensation/templates/compensation/detail/compensation/includes/documents.html:34
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:39
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:39
#: compensation/templates/compensation/detail/eco_account/includes/actions.html:37
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:37
#: compensation/templates/compensation/detail/eco_account/includes/documents.html:34
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:39
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:39
#: compensation/templates/compensation/detail/eco_account/includes/withdraws.html:37
#: ema/templates/ema/detail/includes/actions.html:37
#: ema/templates/ema/detail/includes/deadlines.html:37
#: ema/templates/ema/detail/includes/documents.html:34
#: ema/templates/ema/detail/includes/states-after.html:39
#: ema/templates/ema/detail/includes/states-before.html:39
#: intervention/templates/intervention/detail/includes/compensations.html:36
#: intervention/templates/intervention/detail/includes/documents.html:34
#: intervention/templates/intervention/detail/includes/payments.html:37
#: intervention/templates/intervention/detail/includes/revocation.html:41
#: intervention/templates/intervention/detail/includes/withdraws.html:37
#: templates/log.html:10
msgid "Action"
msgstr "Aktionen"
#: compensation/forms.py:291
msgid "Unit"
msgstr "Einheit"
#: compensation/forms.py:269
#: compensation/forms.py:294
msgid "Select the unit"
msgstr "Einheit wählen"
#: compensation/forms.py:281
#: compensation/forms.py:306
msgid "Insert the amount"
msgstr "Menge eingeben"
#: compensation/forms.py:301
#: compensation/forms.py:326
msgid "New action"
msgstr "Neue Maßnahme"
#: compensation/forms.py:302
#: compensation/forms.py:327
msgid "Insert data for the new action"
msgstr "Geben Sie die Daten der neuen Maßnahme ein"
#: compensation/forms.py:321
#: compensation/forms.py:346
msgid "Added action"
msgstr "Maßnahme hinzugefügt"
@ -226,7 +252,7 @@ msgstr "Kennung"
#: compensation/tables.py:29 compensation/tables.py:169
#: compensation/templates/compensation/detail/compensation/includes/documents.html:28
#: compensation/templates/compensation/detail/compensation/view.html:24
#: compensation/templates/compensation/detail/compensation/view.html:31
#: compensation/templates/compensation/detail/eco_account/includes/documents.html:28
#: compensation/templates/compensation/detail/eco_account/view.html:31
#: ema/tables.py:33 ema/templates/ema/detail/includes/documents.html:28
@ -239,14 +265,14 @@ msgid "Title"
msgstr "Bezeichnung"
#: compensation/tables.py:34
#: compensation/templates/compensation/detail/compensation/view.html:36
#: compensation/templates/compensation/detail/compensation/view.html:43
#: intervention/tables.py:33
#: intervention/templates/intervention/detail/view.html:63 user/models.py:48
msgid "Checked"
msgstr "Geprüft"
#: compensation/tables.py:40 compensation/tables.py:179
#: compensation/templates/compensation/detail/compensation/view.html:50
#: compensation/templates/compensation/detail/compensation/view.html:57
#: compensation/templates/compensation/detail/eco_account/view.html:43
#: ema/tables.py:38 ema/templates/ema/detail/view.html:28
#: intervention/tables.py:39
@ -275,7 +301,7 @@ msgid "Open {}"
msgstr "Öffne {}"
#: compensation/tables.py:83
#: compensation/templates/compensation/detail/compensation/view.html:12
#: compensation/templates/compensation/detail/compensation/view.html:19
#: konova/templates/konova/home.html:49 templates/navbar.html:28
msgid "Compensation"
msgstr "Kompensation"
@ -289,7 +315,7 @@ msgid "Checked on {} by {}"
msgstr "Am {} von {} geprüft worden"
#: compensation/tables.py:128
#: compensation/templates/compensation/detail/compensation/view.html:53
#: compensation/templates/compensation/detail/compensation/view.html:60
#: compensation/templates/compensation/detail/eco_account/view.html:46
#: ema/tables.py:101 ema/templates/ema/detail/view.html:31
#: intervention/tables.py:135
@ -360,31 +386,6 @@ msgctxt "Compensation"
msgid "Amount"
msgstr "Menge"
#: compensation/templates/compensation/detail/compensation/includes/actions.html:37
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:37
#: compensation/templates/compensation/detail/compensation/includes/documents.html:34
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:39
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:39
#: compensation/templates/compensation/detail/eco_account/includes/actions.html:37
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:37
#: compensation/templates/compensation/detail/eco_account/includes/documents.html:34
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:39
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:39
#: compensation/templates/compensation/detail/eco_account/includes/withdraws.html:37
#: ema/templates/ema/detail/includes/actions.html:37
#: ema/templates/ema/detail/includes/deadlines.html:37
#: ema/templates/ema/detail/includes/documents.html:34
#: ema/templates/ema/detail/includes/states-after.html:39
#: ema/templates/ema/detail/includes/states-before.html:39
#: intervention/templates/intervention/detail/includes/compensations.html:36
#: intervention/templates/intervention/detail/includes/documents.html:34
#: intervention/templates/intervention/detail/includes/payments.html:37
#: intervention/templates/intervention/detail/includes/revocation.html:41
#: intervention/templates/intervention/detail/includes/withdraws.html:37
#: templates/log.html:10
msgid "Action"
msgstr "Aktionen"
#: compensation/templates/compensation/detail/compensation/includes/actions.html:51
#: compensation/templates/compensation/detail/eco_account/includes/actions.html:51
#: ema/templates/ema/detail/includes/actions.html:51
@ -527,17 +528,17 @@ msgstr "Neuen Ausgangszustand hinzufügen"
msgid "Missing surfaces according to states after: "
msgstr "Fehlende Flächenmengen laut Zielzustand: "
#: compensation/templates/compensation/detail/compensation/view.html:28
#: compensation/templates/compensation/detail/compensation/view.html:35
msgid "compensates intervention"
msgstr "kompensiert Eingriff"
#: compensation/templates/compensation/detail/compensation/view.html:43
#: compensation/templates/compensation/detail/compensation/view.html:50
#: intervention/templates/intervention/detail/view.html:70
msgid "Checked on "
msgstr "Geprüft am "
#: compensation/templates/compensation/detail/compensation/view.html:43
#: compensation/templates/compensation/detail/compensation/view.html:57
#: compensation/templates/compensation/detail/compensation/view.html:50
#: compensation/templates/compensation/detail/compensation/view.html:64
#: compensation/templates/compensation/detail/eco_account/view.html:50
#: ema/templates/ema/detail/view.html:35
#: intervention/templates/intervention/detail/view.html:70
@ -545,21 +546,21 @@ msgstr "Geprüft am "
msgid "by"
msgstr "von"
#: compensation/templates/compensation/detail/compensation/view.html:57
#: compensation/templates/compensation/detail/compensation/view.html:64
#: compensation/templates/compensation/detail/eco_account/view.html:50
#: ema/templates/ema/detail/view.html:35
#: intervention/templates/intervention/detail/view.html:84
msgid "Recorded on "
msgstr "Verzeichnet am"
#: compensation/templates/compensation/detail/compensation/view.html:64
#: compensation/templates/compensation/detail/compensation/view.html:71
#: compensation/templates/compensation/detail/eco_account/view.html:69
#: ema/templates/ema/detail/view.html:54
#: intervention/templates/intervention/detail/view.html:103
msgid "Last modified"
msgstr "Zuletzt bearbeitet"
#: compensation/templates/compensation/detail/compensation/view.html:72
#: compensation/templates/compensation/detail/compensation/view.html:79
#: compensation/templates/compensation/detail/eco_account/view.html:77
#: ema/templates/ema/detail/view.html:69 intervention/forms.py:255
#: intervention/templates/intervention/detail/view.html:111
@ -903,7 +904,8 @@ msgid ""
"Eco-account {} is not recorded yet. You can only withdraw from recorded "
"accounts."
msgstr ""
"Ökokonto {} ist noch nicht verzeichnet. Abbuchungen können nur von verzeichneten Ökokonten erfolgen."
"Ökokonto {} ist noch nicht verzeichnet. Abbuchungen können nur von "
"verzeichneten Ökokonten erfolgen."
#: intervention/forms.py:544
msgid ""