def validate_num_more_than_1(self, value): if str(value).strip() == '': value = 0 if not isinstance(value, int): try: value = int(value) except ValueError: raise Invalid(u"必须为数字") if value <= 0: raise ValueInvalid(u'必须为大于等于0的数字') return value
def validate_float(self, value): if str(value).strip() == '': value = 0 if not isinstance(value, float): try: value = float(value) except ValueError: raise Invalid(u"必须为数字") # logger.info("value --> %s, value < 0: %s" % (value, (value < 0))) if value < 0: raise ValueInvalid(u'必须为大于等于0的数字') return value
def is_callable(v): if not callable(v): raise ValueInvalid('not a valid value') return v
def strip_str(value): if value is None: raise ValueInvalid("参数不能为空") return str(value).strip()