How to use the sqlobject.include.validators.InvalidField function in SQLObject

To help you get started, we’ve selected a few SQLObject examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def convertMonth(self, value, state):
        match = self._monthDateRE.search(value)
        if not match:
            raise InvalidField(self.message('wrongFormat', 'Please enter the date in the form mm/yyyy'), value, state)
        month = self.makeMonth(match.group(1))
        year = self.makeYear(match.group(2))
        if month > 12 or month < 1:
            raise InvalidField(self.message('monthRange', 'Please enter a month from 1 to 12'), value, state)
        return DateTime.DateTime(year, month)
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def _toPython(self, value, state):
        try:
            value = int(value)
        except ValueError:
            raise InvalidField(self.message('integer', "Must be an integer index"), value, state)
        try:
            return self.list[value]
        except IndexError:
            raise InvalidField(self.message('outOfRange', "Index out of range"), value, state)
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def attemptConvert(self, value, state, pre, convert, post):
        if not value:
            if self.ifEmpty is not NoDefault:
                return self.ifEmpty
            if self.notEmpty:
                raise InvalidField(self.message('empty', "Please enter a value"), value, state)
        try:
            if pre:
                pre(value, state)
            if convert:
                converted = convert(value, state)
            else:
                converted = value
            if post:
                post(value, state)
            return converted
        except InvalidField:
            if self.ifInvalid is NoDefault:
                raise
            else:
                return self.ifInvalid
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def makeYear(self, year):
        try:
            year = int(year)
        except ValueError:
            raise InvalidField(self.message('invalidYear', 'Please enter a number for the year'), value, state)
        if year <= 20:
            year = year + 2000
        if year >= 50 and year < 100:
            year = year + 1900
        if year > 20 and year < 50:
            raise InvalidField(self.message('fourDigitYear', 'Please enter a four-digit year'), value, state)
        return year
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def _fromPython(self, value, state):
        for k, v in self.dict.items():
            if value == v:
                return k
        raise InvalidField("Nothing in my dictionary goes by the value %s"
                           % repr(value), value, state)
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def _fromPython(self, value, state):
        if not isinstance(value, str):
            raise InvalidField('Invalid', value, state)
        match = self._phoneRE.search(value)
        if not match:
            raise InvalidField(self.message('phoneFormat', 'Please enter a number, with area code, in the form ###-###-####, optionally with "ext.####"'),
                               value, state)
        result = '%s-%s-%s' % (match.group(1), match.group(2), match.group(3))
        if match.group(4):
            result = result + " ext.%s" % match.group(4)
        return result
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
if not len(splitted) == 2:
            raise InvalidField(
                self.message('noAt', 'An email address must contain an @'),
                value, state)
        if not self.usernameRE.search(splitted[0]):
            raise InvalidField(
                self.message('badUsername', 'The username portion of the email address is invalid (the portion before the @: %(username)s)') % {"username": htmlEncode(splitted[0])},
                value, state)
        if not self.domainRE.search(splitted[1]):
            raise InvalidField(
                self.message('badDomain', 'The domain portion of the email address is invalid (the portion after the @: %(domain)s)') % {"domain": htmlEncode(splitted[1])},
                value, state)
        if self.resolveDomain:
            domains = mxlookup(splitted[1])
            if not domains:
                raise InvalidField(
                    self.message('domainDoesNotExist', 'The domain of the email address does not exist (the portion after the @: %(domain)s)') % {"domain": splitted[1]},
                    value, state)
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def _toPython(self, valueDict, state):
        v = valueDict.copy()
        try:
            field = v[self.name]
            del v[self.name]
        except KeyError:
            raise InvalidField(self.message('missing', 'The name %(name)s is missing') % {'name': repr(self.name)}, valueDict, state)
        return field, v
github sqlobject / sqlobject / sqlobject / include / validators.py View on Github external
def makeMonth(self, value):
        try:
            return int(value)
        except ValueError:
            value = string.strip(string.lower(value))
            if self._monthNames.has_key(value):
                return self._monthNames[value]
            else:
                raise InvalidField(self.message('unknownMonthName', "Unknown month name: %(month)s") % {"month": value}, value, state)