update validators and wording

This commit is contained in:
2021-05-06 16:39:29 +00:00
parent f6bb6ae877
commit d6de6218c3
5 changed files with 211 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
from django.core.validators import RegexValidator, ValidationError
from django.utils.deconstruct import deconstructible
from django.utils.translation import gettext_lazy as _
@deconstructible
class PhoneNumberValidator(RegexValidator):
regex = r"^\+?1?\d{9,15}$"
message = _(
"Telefonnummer muss in diesem Format +999999999999 eingegeben werden. "
"Bis zu 15 Zahlen sind erlaubt."
)
def validate_domainonly_email(value):
if not "fet.at" in value:
raise ValidationError(_("In der Mailadresse fehlt die richtige Domäne."))
def validate_file_size(value):
if value.size > 10 * 1024 * 1024:
raise ValidationError(_("Die maximale Dateigröße ist 10MB."))
def validate_image_dimension(value):
if value.height < 150 or value.width < 150:
raise ValidationError(
_("Das Bild ist zu klein. (Höhe: %(height)s, Breite: %(width)s)"),
params={
"height": value.height,
"width": value.width,
}
)