Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
 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, '')
Exemple #4
0
 def validate_email(self, value):
     if not re.match('[^@]+@[^@]+\.[^@]+', value):
         raise nfw.FieldError(self._name, self.label, 'invalid email value',
                              value)
Exemple #5
0
 def is_string(self, value):
     if not isinstance(value, basestring):
         raise nfw.FieldError(self._name, self.label,
                              'invalid string value', value)
Exemple #6
0
 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)
Exemple #7
0
 def is_bool(self, value):
     if not isinstance(value, (int, long, float, bool)):
         raise nfw.FieldError(self._name, self.label,
                              'invalid boolean value', value)
Exemple #8
0
 def is_number(self, value):
     if not isinstance(value, (int, long, float)):
         raise nfw.FieldError(self._name, self.label,
                              'invalid number value', value)
Exemple #9
0
 def is_integer(self, value):
     if not isinstance(value, (int, long)):
         raise nfw.FieldError(self._name, self.label,
                              'invalid integer value', value)
Exemple #10
0
 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)