# 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
This commit is contained in:
2023-05-17 14:08:57 +02:00
parent 67e050764b
commit 9136b89e00
11 changed files with 79 additions and 28 deletions

View File

@@ -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},
)