ska-referee-test/ref-test/admin/models/forms/validators.py

11 lines
312 B
Python
Raw Normal View History

from wtforms.validators import ValidationError
def value(min=0, max=None):
message = f'Value must be between {min} and {max}.'
def _length(form, field):
value = field.data or 0
if value < min or max != None and value > max:
raise ValidationError(message)
return _length