|
|
@ -88,54 +88,54 @@ class FormDefinition: |
|
|
|
|
|
|
|
|
|
|
|
def validate_integer(self, field_def, form_values): |
|
|
|
def validate_integer(self, field_def, form_values): |
|
|
|
value = form_values[field_def['name']] |
|
|
|
value = form_values[field_def['name']] |
|
|
|
max = field_def.get('max', None) |
|
|
|
_max = field_def.get('max', None) |
|
|
|
min = field_def.get('min', None) |
|
|
|
_min = field_def.get('min', None) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
value = int(value) |
|
|
|
value = int(value) |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
raise ValidationError("Must be an integer number") |
|
|
|
raise ValidationError("Must be an integer number") |
|
|
|
|
|
|
|
|
|
|
|
if min is not None and value < int(min): |
|
|
|
if _min is not None and value < int(_min): |
|
|
|
raise ValidationError("Minimum value is {0}".format(min)) |
|
|
|
raise ValidationError("Minimum value is {0}".format(_min)) |
|
|
|
if max is not None and value > int(max): |
|
|
|
if _max is not None and value > int(_max): |
|
|
|
raise ValidationError("Maximum value is {0}".format(max)) |
|
|
|
raise ValidationError("Maximum value is {0}".format(_max)) |
|
|
|
|
|
|
|
|
|
|
|
return int(value) |
|
|
|
return int(value) |
|
|
|
|
|
|
|
|
|
|
|
def validate_float(self, field_def, form_values): |
|
|
|
def validate_float(self, field_def, form_values): |
|
|
|
value = form_values[field_def['name']] |
|
|
|
value = form_values[field_def['name']] |
|
|
|
max = field_def.get('max', None) |
|
|
|
_max = field_def.get('max', None) |
|
|
|
min = field_def.get('min', None) |
|
|
|
_min = field_def.get('min', None) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
value = float(value) |
|
|
|
value = float(value) |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
raise ValidationError("Must be an real (float) number") |
|
|
|
raise ValidationError("Must be an real (float) number") |
|
|
|
|
|
|
|
|
|
|
|
if min is not None and value < float(min): |
|
|
|
if _min is not None and value < float(_min): |
|
|
|
raise ValidationError("Minimum value is {0}".format(min)) |
|
|
|
raise ValidationError("Minimum value is {0}".format(_min)) |
|
|
|
if max is not None and value > float(max): |
|
|
|
if _max is not None and value > float(_max): |
|
|
|
raise ValidationError("Maximum value is {0}".format(max)) |
|
|
|
raise ValidationError("Maximum value is {0}".format(_max)) |
|
|
|
|
|
|
|
|
|
|
|
return float(value) |
|
|
|
return float(value) |
|
|
|
|
|
|
|
|
|
|
|
def validate_date(self, field_def, form_values): |
|
|
|
def validate_date(self, field_def, form_values): |
|
|
|
value = form_values[field_def['name']] |
|
|
|
value = form_values[field_def['name']] |
|
|
|
max = field_def.get('max', None) |
|
|
|
_max = field_def.get('max', None) |
|
|
|
min = field_def.get('min', None) |
|
|
|
_min = field_def.get('min', None) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
try: |
|
|
|
value = datetime.datetime.strptime(value, '%Y-%m-%d').date() |
|
|
|
value = datetime.datetime.strptime(value, '%Y-%m-%d').date() |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
raise ValidationError("Invalid date, must be in form YYYY-MM-DD") |
|
|
|
raise ValidationError("Invalid date, must be in form YYYY-MM-DD") |
|
|
|
|
|
|
|
|
|
|
|
if min is not None: |
|
|
|
if _min is not None: |
|
|
|
if value < datetime.datetime.strptime(min, '%Y-%m-%d').date(): |
|
|
|
if value < datetime.datetime.strptime(_min, '%Y-%m-%d').date(): |
|
|
|
raise ValidationError("Minimum value is {0}".format(min)) |
|
|
|
raise ValidationError("Minimum value is {0}".format(_min)) |
|
|
|
if max is not None: |
|
|
|
if _max is not None: |
|
|
|
if value > datetime.datetime.strptime(max, '%Y-%m-%d').date(): |
|
|
|
if value > datetime.datetime.strptime(_max, '%Y-%m-%d').date(): |
|
|
|
raise ValidationError("Maximum value is {0}".format(max)) |
|
|
|
raise ValidationError("Maximum value is {0}".format(_max)) |
|
|
|
|
|
|
|
|
|
|
|
return value |
|
|
|
return value |
|
|
|
|
|
|
|
|
|
|
|