mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 23:04:21 +00:00
26 lines
775 B
Python
26 lines
775 B
Python
from django.core.validators import ValidationError
|
|
from django.utils.deconstruct import deconstructible
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
@deconstructible
|
|
class DisallowedValuesValidator:
|
|
def __init__(self, values):
|
|
self.values = values
|
|
|
|
def __call__(self, value):
|
|
if value in self.values:
|
|
raise ValidationError(
|
|
_("%(value)s is a disallowed value."),
|
|
params={"value": value},
|
|
)
|
|
|
|
|
|
@deconstructible
|
|
class NotStartingWithDashValidator:
|
|
def __call__(self, value):
|
|
if value.startswith("-") or value.endswith("-"):
|
|
raise ValidationError(
|
|
_("%(value)s starts or ends with a dash."),
|
|
params={"value": value},
|
|
)
|