# 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:
28
konova/utils/validators.py
Normal file
28
konova/utils/validators.py
Normal 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},
|
||||
)
|
||||
Reference in New Issue
Block a user