def is_size(self, value): if (self.maximum is not None and value > self.maximum): raise nfw.FieldError(self._name, self.label, 'exceeded maximum value', self.maximum) if (self.minimum is not None and value < self.minimum): raise nfw.FieldError(self._name, self.label, 'less than minimum value', self.minimum)
def validate_length(self, value): if (self.max_length is not None and self.max_length != 0 and len(value) > self.max_length): raise nfw.FieldError(self._name, self.label, 'exceeded maximum length', self.max_length) if len(value) < self.min_length: raise nfw.FieldError(self._name, self.label, 'less than required length', self.min_length)
def validate_password(self, value): # Password secure enoguh lowerCharCount = 0 higherCharCount = 0 intCount = 0 symCount = 0 for letter in value: if re.search(r'\d', letter): intCount += 1 elif re.search(r'[A-Z]', letter): higherCharCount += 1 elif re.search(r'[a-z]', letter): lowerCharCount += 1 else: symCount += 1 error = None if intCount < 1: error = "1 numbers" if lowerCharCount < 1: if error is not None: error = "%s, 1 lower case characters" % (error) if error is None: error = "1 lower case characters" if higherCharCount < 1: if error is not None: error = "%s, 1 upper case characters" % (error) if error is None: error = "1 upper case characters" if error is not None: raise nfw.FieldError(self._name, self.label, error, '')
def validate_email(self, value): if not re.match('[^@]+@[^@]+\.[^@]+', value): raise nfw.FieldError(self._name, self.label, 'invalid email value', value)
def is_string(self, value): if not isinstance(value, basestring): raise nfw.FieldError(self._name, self.label, 'invalid string value', value)
def is_uuid(self, value): if not isinstance(value, basestring) or len(value) != 36: raise nfw.FieldError(self._name, self.label, 'invalid uuid value', value)
def is_bool(self, value): if not isinstance(value, (int, long, float, bool)): raise nfw.FieldError(self._name, self.label, 'invalid boolean value', value)
def is_number(self, value): if not isinstance(value, (int, long, float)): raise nfw.FieldError(self._name, self.label, 'invalid number value', value)
def is_integer(self, value): if not isinstance(value, (int, long)): raise nfw.FieldError(self._name, self.label, 'invalid integer value', value)
def is_datetime(self, value): if (not isinstance(value, datetime) and not isinstance(value, basestring)): raise nfw.FieldError(self._name, self.label, 'invalid datetime value', value)