validation_float.py
739 Bytes
from .base_validation import BaseValidation
class ValidationFloat(BaseValidation):
def __init__(self, cldr, params = {}):
super(ValidationFloat, self).__init__(cldr = cldr, params = params)
self.__message = self.rulemessage or ':attribute harus berupa angka bilangan bulat atau desimal.'
def validate(self):
ok = True
if (self.value is None) or (self.value == ''):
ok = not self.required
else:
try:
val = float(self.value)
except ValueError:
ok = False
if not ok:
self.colander_invalid[self.inputname] = self.__message.replace(':attribute', self.title)
return ok