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