# Improves form date checking

* adds validator to make sure no dates like `01.01.1` can be accepted. All dates must be somewhat later than 01.01.1950
pull/335/head
mpeltriaux 1 year ago
parent c604de0f32
commit 9544e27baf

@ -13,6 +13,7 @@ from django.utils.translation import gettext_lazy as _
from codelist.models import KonovaCode from codelist.models import KonovaCode
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
from konova.forms import BaseForm from konova.forms import BaseForm
from konova.utils import validators
class TimespanReportForm(BaseForm): class TimespanReportForm(BaseForm):
@ -22,6 +23,7 @@ class TimespanReportForm(BaseForm):
date_from = forms.DateField( date_from = forms.DateField(
label_suffix="", label_suffix="",
label=_("From"), label=_("From"),
validators=[validators.reasonable_date],
help_text=_("Entries created from..."), help_text=_("Entries created from..."),
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
@ -35,6 +37,7 @@ class TimespanReportForm(BaseForm):
date_to = forms.DateField( date_to = forms.DateField(
label_suffix="", label_suffix="",
label=_("To"), label=_("To"),
validators=[validators.reasonable_date],
help_text=_("Entries created until..."), help_text=_("Entries created until..."),
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={

@ -15,6 +15,7 @@ from compensation.models import EcoAccount
from intervention.models import Handler, Responsibility, Legal from intervention.models import Handler, Responsibility, Legal
from konova.forms import SimpleGeomForm from konova.forms import SimpleGeomForm
from konova.forms.modals import RemoveModalForm from konova.forms.modals import RemoveModalForm
from konova.utils import validators
from user.models import User, UserActionLogEntry from user.models import User, UserActionLogEntry
@ -43,6 +44,7 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
label_suffix="", label_suffix="",
help_text=_("When did the parties agree on this?"), help_text=_("When did the parties agree on this?"),
required=False, required=False,
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
from konova.forms.modals import BaseModalForm from konova.forms.modals import BaseModalForm
from konova.models import DeadlineType from konova.models import DeadlineType
from konova.utils import validators
from konova.utils.message_templates import DEADLINE_EDITED from konova.utils.message_templates import DEADLINE_EDITED
@ -34,6 +35,7 @@ class NewDeadlineModalForm(BaseModalForm):
label_suffix="", label_suffix="",
required=True, required=True,
help_text=_("Select date"), help_text=_("Select date"),
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -9,6 +9,7 @@ from django import forms
from django.utils.translation import pgettext_lazy as _con, gettext_lazy as _ from django.utils.translation import pgettext_lazy as _con, gettext_lazy as _
from konova.forms.modals import RemoveModalForm, BaseModalForm from konova.forms.modals import RemoveModalForm, BaseModalForm
from konova.utils import validators
from konova.utils.message_templates import PAYMENT_EDITED from konova.utils.message_templates import PAYMENT_EDITED
@ -33,6 +34,7 @@ class NewPaymentForm(BaseModalForm):
label=_("Due on"), label=_("Due on"),
label_suffix=_(""), label_suffix=_(""),
required=False, required=False,
validators=[validators.reasonable_date],
help_text=_("Due on which date"), help_text=_("Due on which date"),
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={

@ -9,6 +9,7 @@ from dal import autocomplete
from django import forms from django import forms
from konova.forms.base_form import BaseForm from konova.forms.base_form import BaseForm
from konova.utils import validators
from konova.utils.message_templates import EDITED_GENERAL_DATA from konova.utils.message_templates import EDITED_GENERAL_DATA
from user.models import User from user.models import User
from django.db import transaction from django.db import transaction
@ -175,6 +176,7 @@ class NewInterventionForm(BaseForm):
label=_("Registration date"), label=_("Registration date"),
label_suffix=_(""), label_suffix=_(""),
required=False, required=False,
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",
@ -187,6 +189,7 @@ class NewInterventionForm(BaseForm):
label=_("Binding on"), label=_("Binding on"),
label_suffix=_(""), label_suffix=_(""),
required=False, required=False,
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -11,6 +11,7 @@ from django.utils.translation import gettext_lazy as _
from intervention.models import RevocationDocument from intervention.models import RevocationDocument
from konova.forms.modals import BaseModalForm, RemoveModalForm from konova.forms.modals import BaseModalForm, RemoveModalForm
from konova.utils import validators
from konova.utils.message_templates import REVOCATION_ADDED, REVOCATION_EDITED from konova.utils.message_templates import REVOCATION_ADDED, REVOCATION_EDITED
@ -19,6 +20,7 @@ class NewRevocationModalForm(BaseModalForm):
label=_("Date"), label=_("Date"),
label_suffix=_(""), label_suffix=_(""),
help_text=_("Date of revocation"), help_text=_("Date of revocation"),
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -12,6 +12,7 @@ from django.utils.translation import gettext_lazy as _
from konova.forms.modals.base_form import BaseModalForm from konova.forms.modals.base_form import BaseModalForm
from konova.models import AbstractDocument from konova.models import AbstractDocument
from konova.utils import validators
from konova.utils.message_templates import DOCUMENT_EDITED, FILE_SIZE_TOO_LARGE, FILE_TYPE_UNSUPPORTED from konova.utils.message_templates import DOCUMENT_EDITED, FILE_SIZE_TOO_LARGE, FILE_TYPE_UNSUPPORTED
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
@ -34,6 +35,7 @@ class NewDocumentModalForm(BaseModalForm):
label=_("Created on"), label=_("Created on"),
label_suffix=_(""), label_suffix=_(""),
help_text=_("When has this file been created? Important for photos."), help_text=_("When has this file been created? Important for photos."),
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -14,6 +14,7 @@ from django.utils.translation import gettext_lazy as _
from konova.forms.modals.base_form import BaseModalForm from konova.forms.modals.base_form import BaseModalForm
from konova.models import Resubmission from konova.models import Resubmission
from konova.utils import validators
class ResubmissionModalForm(BaseModalForm): class ResubmissionModalForm(BaseModalForm):
@ -21,6 +22,7 @@ class ResubmissionModalForm(BaseModalForm):
label_suffix=_(""), label_suffix=_(""),
label=_("Date"), label=_("Date"),
help_text=_("When do you want to be reminded?"), help_text=_("When do you want to be reminded?"),
validators=[validators.reasonable_date],
widget=forms.DateInput( widget=forms.DateInput(
attrs={ attrs={
"type": "date", "type": "date",

@ -0,0 +1,28 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 17.05.23
"""
from datetime import datetime
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
def reasonable_date(value):
""" Validator which checks that no dates like "01.01.1" can be entered
Args:
value ():
Returns:
"""
min_date = datetime.fromisoformat("1950-01-01").date()
if value < min_date:
raise ValidationError(
_("This date is unrealistic. Please enter the correct date (>1950)."),
params={"value": value},
)

Binary file not shown.

@ -5,7 +5,7 @@
# #
#: compensation/filters/eco_account.py:21 #: compensation/filters/eco_account.py:21
#: compensation/forms/modals/compensation_action.py:82 #: compensation/forms/modals/compensation_action.py:82
#: compensation/forms/modals/deadline.py:50 #: compensation/forms/modals/deadline.py:52
#: compensation/forms/modals/payment.py:23 #: compensation/forms/modals/payment.py:23
#: compensation/forms/modals/payment.py:34 #: compensation/forms/modals/payment.py:34
#: compensation/forms/modals/payment.py:50 #: compensation/forms/modals/payment.py:50
@ -43,7 +43,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-07 07:09+0100\n" "POT-Creation-Date: 2023-05-17 12:42+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -72,7 +72,7 @@ msgstr "Einträge erstellt bis..."
#: analysis/forms.py:49 compensation/forms/mixins.py:21 #: analysis/forms.py:49 compensation/forms/mixins.py:21
#: compensation/templates/compensation/detail/eco_account/view.html:59 #: compensation/templates/compensation/detail/eco_account/view.html:59
#: compensation/templates/compensation/report/eco_account/report.html:16 #: compensation/templates/compensation/report/eco_account/report.html:16
#: compensation/utils/quality.py:112 ema/templates/ema/detail/view.html:49 #: compensation/utils/quality.py:113 ema/templates/ema/detail/view.html:49
#: ema/templates/ema/report/report.html:16 ema/utils/quality.py:26 #: ema/templates/ema/report/report.html:16 ema/utils/quality.py:26
#: intervention/forms/intervention.py:104 #: intervention/forms/intervention.py:104
#: intervention/templates/intervention/detail/view.html:56 #: intervention/templates/intervention/detail/view.html:56
@ -398,7 +398,7 @@ msgstr "Kompensation XY; Flur ABC"
#: compensation/forms/compensation.py:56 #: compensation/forms/compensation.py:56
#: compensation/forms/modals/compensation_action.py:81 #: compensation/forms/modals/compensation_action.py:81
#: compensation/forms/modals/deadline.py:49 #: compensation/forms/modals/deadline.py:51
#: compensation/forms/modals/payment.py:49 #: compensation/forms/modals/payment.py:49
#: compensation/templates/compensation/detail/compensation/includes/actions.html:35 #: compensation/templates/compensation/detail/compensation/includes/actions.html:35
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:39 #: compensation/templates/compensation/detail/compensation/includes/deadlines.html:39
@ -446,7 +446,7 @@ msgstr "Neue Kompensation"
msgid "Edit compensation" msgid "Edit compensation"
msgstr "Bearbeite Kompensation" msgstr "Bearbeite Kompensation"
#: compensation/forms/eco_account.py:30 compensation/utils/quality.py:96 #: compensation/forms/eco_account.py:30 compensation/utils/quality.py:97
msgid "Available Surface" msgid "Available Surface"
msgstr "Verfügbare Fläche" msgstr "Verfügbare Fläche"
@ -486,7 +486,7 @@ msgstr ""
#: compensation/forms/mixins.py:37 #: compensation/forms/mixins.py:37
#: compensation/templates/compensation/detail/eco_account/view.html:63 #: compensation/templates/compensation/detail/eco_account/view.html:63
#: compensation/templates/compensation/report/eco_account/report.html:20 #: compensation/templates/compensation/report/eco_account/report.html:20
#: compensation/utils/quality.py:114 ema/templates/ema/detail/view.html:53 #: compensation/utils/quality.py:115 ema/templates/ema/detail/view.html:53
#: ema/templates/ema/report/report.html:20 ema/utils/quality.py:28 #: ema/templates/ema/report/report.html:20 ema/utils/quality.py:28
#: intervention/forms/intervention.py:132 #: intervention/forms/intervention.py:132
#: intervention/templates/intervention/detail/view.html:60 #: intervention/templates/intervention/detail/view.html:60
@ -604,15 +604,15 @@ msgstr "Geben Sie die Daten der neuen Maßnahme ein"
msgid "Edit action" msgid "Edit action"
msgstr "Maßnahme bearbeiten" msgstr "Maßnahme bearbeiten"
#: compensation/forms/modals/deadline.py:21 #: compensation/forms/modals/deadline.py:23
msgid "Deadline Type" msgid "Deadline Type"
msgstr "Fristart" msgstr "Fristart"
#: compensation/forms/modals/deadline.py:24 #: compensation/forms/modals/deadline.py:26
msgid "Select the deadline type" msgid "Select the deadline type"
msgstr "Fristart wählen" msgstr "Fristart wählen"
#: compensation/forms/modals/deadline.py:33 #: compensation/forms/modals/deadline.py:35
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:36 #: compensation/templates/compensation/detail/compensation/includes/deadlines.html:36
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:36 #: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:36
#: ema/templates/ema/detail/includes/deadlines.html:36 #: ema/templates/ema/detail/includes/deadlines.html:36
@ -621,26 +621,30 @@ msgstr "Fristart wählen"
msgid "Date" msgid "Date"
msgstr "Datum" msgstr "Datum"
#: compensation/forms/modals/deadline.py:36 #: compensation/forms/modals/deadline.py:38
msgid "Select date" msgid "Select date"
msgstr "Datum wählen" msgstr "Datum wählen"
#: compensation/forms/modals/deadline.py:51 #: compensation/forms/modals/deadline.py:53
#: compensation/forms/modals/payment.py:51 #: compensation/forms/modals/payment.py:51
#: intervention/forms/modals/revocation.py:47 #: intervention/forms/modals/revocation.py:47
#: konova/forms/modals/document_form.py:61 #: konova/forms/modals/document_form.py:61
msgid "Additional comment, maximum {} letters" msgid "Additional comment, maximum {} letters"
msgstr "Zusätzlicher Kommentar, maximal {} Zeichen" msgstr "Zusätzlicher Kommentar, maximal {} Zeichen"
#: compensation/forms/modals/deadline.py:63 #: compensation/forms/modals/deadline.py:65
msgid "New deadline" msgid "New deadline"
msgstr "Neue Frist" msgstr "Neue Frist"
#: compensation/forms/modals/deadline.py:64 #: compensation/forms/modals/deadline.py:66
msgid "Insert data for the new deadline" msgid "Insert data for the new deadline"
msgstr "Geben Sie die Daten der neuen Frist ein" msgstr "Geben Sie die Daten der neuen Frist ein"
#: compensation/forms/modals/deadline.py:77 #: compensation/forms/modals/deadline.py:77
msgid "This date is unrealistic. Please enter the correct date (>1950)."
msgstr "Dieses Datum ist unrealistisch. Geben Sie bitte das korrekte Datum ein (>1950)."
#: compensation/forms/modals/deadline.py:95
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:64 #: compensation/templates/compensation/detail/compensation/includes/deadlines.html:64
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:62 #: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:62
#: ema/templates/ema/detail/includes/deadlines.html:62 #: ema/templates/ema/detail/includes/deadlines.html:62
@ -1262,13 +1266,13 @@ msgstr "Umsetzungstermin"
msgid "Legal data" msgid "Legal data"
msgstr "Rechtliche Daten" msgstr "Rechtliche Daten"
#: compensation/utils/quality.py:100 #: compensation/utils/quality.py:101
msgid "Deductable surface can not be larger than state surface" msgid "Deductable surface can not be larger than state surface"
msgstr "" msgstr ""
"Die abbuchbare Fläche darf die Gesamtfläche der Zielzustände nicht " "Die abbuchbare Fläche darf die Gesamtfläche der Zielzustände nicht "
"überschreiten" "überschreiten"
#: compensation/utils/quality.py:116 ema/utils/quality.py:30 #: compensation/utils/quality.py:117 ema/utils/quality.py:30
#: intervention/utils/quality.py:68 #: intervention/utils/quality.py:68
msgid "Responsible data" msgid "Responsible data"
msgstr "Daten zu den verantwortlichen Stellen" msgstr "Daten zu den verantwortlichen Stellen"
@ -1283,7 +1287,7 @@ msgid "Compensation {} edited"
msgstr "Kompensation {} bearbeitet" msgstr "Kompensation {} bearbeitet"
#: compensation/views/compensation/compensation.py:187 #: compensation/views/compensation/compensation.py:187
#: compensation/views/eco_account/eco_account.py:161 ema/views/ema.py:212 #: compensation/views/eco_account/eco_account.py:161 ema/views/ema.py:220
#: intervention/views/intervention.py:243 #: intervention/views/intervention.py:243
msgid "Edit {}" msgid "Edit {}"
msgstr "Bearbeite {}" msgstr "Bearbeite {}"
@ -1306,11 +1310,11 @@ msgstr "Ökokonto {} hinzugefügt"
msgid "Eco-Account {} edited" msgid "Eco-Account {} edited"
msgstr "Ökokonto {} bearbeitet" msgstr "Ökokonto {} bearbeitet"
#: compensation/views/eco_account/eco_account.py:268 #: compensation/views/eco_account/eco_account.py:275
msgid "Eco-account removed" msgid "Eco-account removed"
msgstr "Ökokonto entfernt" msgstr "Ökokonto entfernt"
#: ema/forms.py:42 ema/views/ema.py:95 #: ema/forms.py:42 ema/views/ema.py:96
msgid "New EMA" msgid "New EMA"
msgstr "Neue EMA hinzufügen" msgstr "Neue EMA hinzufügen"
@ -1338,19 +1342,19 @@ msgstr ""
msgid "Payment funded compensation" msgid "Payment funded compensation"
msgstr "Ersatzzahlungsmaßnahme" msgstr "Ersatzzahlungsmaßnahme"
#: ema/views/ema.py:52 #: ema/views/ema.py:53
msgid "EMAs - Overview" msgid "EMAs - Overview"
msgstr "EMAs - Übersicht" msgstr "EMAs - Übersicht"
#: ema/views/ema.py:85 #: ema/views/ema.py:86
msgid "EMA {} added" msgid "EMA {} added"
msgstr "EMA {} hinzugefügt" msgstr "EMA {} hinzugefügt"
#: ema/views/ema.py:202 #: ema/views/ema.py:210
msgid "EMA {} edited" msgid "EMA {} edited"
msgstr "EMA {} bearbeitet" msgstr "EMA {} bearbeitet"
#: ema/views/ema.py:236 #: ema/views/ema.py:244
msgid "EMA removed" msgid "EMA removed"
msgstr "EMA entfernt" msgstr "EMA entfernt"
@ -2095,7 +2099,8 @@ msgid ""
"Do not forget to share your entry! Currently you are the only one having " "Do not forget to share your entry! Currently you are the only one having "
"shared access." "shared access."
msgstr "" msgstr ""
"Denken Sie daran Ihren Eintrag freizugeben! Aktuell haben nur Sie eine Freigabe hierauf." "Denken Sie daran Ihren Eintrag freizugeben! Aktuell haben nur Sie eine "
"Freigabe hierauf."
#: konova/utils/message_templates.py:29 #: konova/utils/message_templates.py:29
msgid "Unsupported file type" msgid "Unsupported file type"
@ -2270,7 +2275,7 @@ msgstr "Für Sie freigegeben - Datensatz kann bearbeitet werden"
msgid "Access not granted" msgid "Access not granted"
msgstr "Nicht freigegeben - Datensatz nur lesbar" msgstr "Nicht freigegeben - Datensatz nur lesbar"
#: konova/views/home.py:80 templates/navbars/navbar.html:16 #: konova/views/home.py:74 templates/navbars/navbar.html:16
msgid "Home" msgid "Home"
msgstr "Home" msgstr "Home"
@ -2306,15 +2311,15 @@ msgstr "{} ist nun für Sie freigegeben"
msgid "Share link invalid" msgid "Share link invalid"
msgstr "Freigabelink ungültig" msgstr "Freigabelink ungültig"
#: news/models.py:12 #: news/models.py:13
msgid "Default" msgid "Default"
msgstr "Standard" msgstr "Standard"
#: news/models.py:13 #: news/models.py:14
msgid "Info" msgid "Info"
msgstr "" msgstr ""
#: news/models.py:14 #: news/models.py:15
msgid "Warning" msgid "Warning"
msgstr "Warnung" msgstr "Warnung"
@ -2330,7 +2335,7 @@ msgstr "Ältere ..."
msgid "All" msgid "All"
msgstr "Alle" msgstr "Alle"
#: news/templates/news/index.html:9 news/views.py:34 #: news/templates/news/index.html:9 news/views.py:27
msgid "News" msgid "News"
msgstr "Neuigkeiten" msgstr "Neuigkeiten"

Loading…
Cancel
Save