app/views/field.py
def _first_valid(self, params):
        """
        Tries to find the first valid field in params that fits the set criteria.
        returns/raises the default value if none was found
        """
        self._used = None
        for key in self._keys:
            val = params.get(key)
            if val is None:
                continue
            try:
                val = simplejson.loads(val)
            except simplejson.JSONDecodeError:
                continue

            # Make sure that only a valid type is returned
            if Field.SETTINGS_LIST in self._settings:
                # Check every single value for validity
                valid = True

                result = []
                for index in range(len(val)):
                    value = val[index]

                    if not Field.type_checker(self._type)(value):
                        try:
                            val[index] = self._type(value)
                        except TypeError:
                            valid = False
                            continue
                    valid = self._validate_val(value) and valid

                    if valid:
                        result.append(value)
                    elif not Field.SETTINGS_LIST_FILTERED in self._settings:
                        # Break out early in case we're failing as the default
                        break

                if valid or Field.SETTINGS_LIST_FILTERED in self._settings:
                    if not len(result) and Field.SETTINGS_LIST_NON_EMPTY in self._settings:
                        break
                    self._used = key
                    return result
            else:
                valid = True
                if not Field.type_checker(self._type)(val):
                    try:
                        val = self._type(val)
                    except TypeError:
                        valid = False
                if valid and self._validate_val(val):
                    self._used = key
                    return val

        # Since nothing was found the default applies
        if (type(self._default) == type(FieldError) and
                issubclass(self._default, FieldError)):
            raise self._default({
                "name": self._name,
                "keys": self._keys,
                "input": params,
            })
        return self._default

        Tries to find the first valid field in params that fits the set criteria.
        returns/raises the default value if none was found
        
Tries to find the first valid field in params that fits the set criteria.
returns/raises the default value if none was found
Tries to find the first valid field in params that fits the set criteria . returns / raises the default value if none was found
def _first_valid(self, params):
        self._used = None
        for key in self._keys:
            val = params.get(key)
            if val is None:
                continue
            try:
                val = simplejson.loads(val)
            except simplejson.JSONDecodeError:
                continue
            if Field.SETTINGS_LIST in self._settings:
                valid = True
                result = []
                for index in range(len(val)):
                    value = val[index]
                    if not Field.type_checker(self._type)(value):
                        try:
                            val[index] = self._type(value)
                        except TypeError:
                            valid = False
                            continue
                    valid = self._validate_val(value) and valid
                    if valid:
                        result.append(value)
                    elif not Field.SETTINGS_LIST_FILTERED in self._settings:
                        break
                if valid or Field.SETTINGS_LIST_FILTERED in self._settings:
                    if not len(result) and Field.SETTINGS_LIST_NON_EMPTY in self._settings:
                        break
                    self._used = key
                    return result
            else:
                valid = True
                if not Field.type_checker(self._type)(val):
                    try:
                        val = self._type(val)
                    except TypeError:
                        valid = False
                if valid and self._validate_val(val):
                    self._used = key
                    return val
        if (type(self._default) == type(FieldError) and
                issubclass(self._default, FieldError)):
            raise self._default({
                "name": self._name,
                "keys": self._keys,
                "input": params,
            })
        return self._default
def _first_valid ( self , params ) : self . _used = None for key in self . _keys : val = params . get ( key ) if val is None : continue try : val = simplejson . loads ( val ) except simplejson . JSONDecodeError : continue if Field . SETTINGS_LIST in self . _settings : valid = True result = [ ] for index in range ( len ( val ) ) : value = val [ index ] if not Field . type_checker ( self . _type ) ( value ) : try : val [ index ] = self . _type ( value ) except TypeError : valid = False continue valid = self . _validate_val ( value ) and valid if valid : result . append ( value ) elif not Field . SETTINGS_LIST_FILTERED in self . _settings : break if valid or Field . SETTINGS_LIST_FILTERED in self . _settings : if not len ( result ) and Field . SETTINGS_LIST_NON_EMPTY in self . _settings : break self . _used = key return result else : valid = True if not Field . type_checker ( self . _type ) ( val ) : try : val = self . _type ( val ) except TypeError : valid = False if valid and self . _validate_val ( val ) : self . _used = key return val if ( type ( self . _default ) == type ( FieldError ) and issubclass ( self . _default , FieldError ) ) : raise self . _default ( { "name" : self . _name , "keys" : self . _keys , "input" : params , } ) return self . _default
Tries to find the first valid field in params that fits the set criteria.
Tries to find the first valid field in params that fits the set criteria .
"""
        Tries to find the first valid field in params that fits the set criteria.
        returns/raises the default value if none was found
        """ # Make sure that only a valid type is returned # Check every single value for validity # Break out early in case we're failing as the default # Since nothing was found the default applies
self
params