示例#1
0
 def _to_python(self, value, state):
     value = super(DeprecatedNotOneValidator, self)._to_python(
         value, state)
     if value == self.number:
         raise Invalid(self.message(
             'custom', state, number=self.number), value, state)
     return value
 def _attempt_convert(self, value, state, validate):
     value = super(AllAndNotOneValidator,
                   self)._attempt_convert(value, state, validate)
     if value == self.number:
         raise Invalid(self.message('custom', state, number=self.number),
                       value, state)
     return value
示例#3
0
 def validate_python(self, value, state):
     response = captcha.submit(state.POST.get('recaptcha_challenge_field'),
                               value,
                               state.registry.settings['recaptcha.private'],
                               state.environ['REMOTE_ADDR'])
     if not response.is_valid:
         raise Invalid(self.message(response.error_code, state), value,
                       state)
示例#4
0
 def _to_python(self, value, state=None):
     try:
         filename = value.filename
     except AttributeError:
         filename = None
     if not filename and self.not_empty:
         raise Invalid(self.message('notEmpty', state), value, state)
     return value
示例#5
0
 def _to_python(self, value, state):
     """Parse a string and return a datetime object."""
     if value and isinstance(value, datetime):
         return value
     else:
         try:
             format = self.format
             if callable(format):
                 format = format()
             tpl = time.strptime(value, format)
         except ValueError:
             raise Invalid(self.message('badFormat', state), value, state)
         # shoudn't use time.mktime() because it can give OverflowError,
         # depending on the date (e.g. pre 1970) and underlying C library
         return datetime(year=tpl.tm_year, month=tpl.tm_mon, day=tpl.tm_mday,
                 hour=tpl.tm_hour, minute=tpl.tm_min, second=tpl.tm_sec)
示例#6
0
 def _validate_python(self, value_dict, state=None):
     if 'join_type' not in value_dict.keys() and 'join_other_col' not in value_dict.keys() \
             and 'join_self_col' not in value_dict.keys():
         return None
     else:
         extraction = tmpl_context.extraction
         df = extraction.sample
         try:
             dataset = DBSession.query(DataSet).get(
                 int(value_dict['datasetid']))
             pd.merge(df,
                      dataset.sample,
                      how=value_dict['join_type'],
                      left_on=value_dict['join_other_col'],
                      right_on=value_dict['join_self_col'],
                      suffixes=('', '_j_' + dataset.name.lower()))
             return None
         except ValueError as ex:
             raise Invalid(ex.__repr__(), value_dict, state, error_dict={})
示例#7
0
文件: __init__.py 项目: isaleem/cumin
class email_list_validator(FancyValidator):
    def __init__(self, *args, **kwargs):
        FancyValidator.__init__(self, *args, **kwargs)
        self.email = Email()

    def _to_python(self, value, state=None):
        """Validate a comma separated list of email addresses."""
        emails = [x.strip() for x in value.split(',')]
        good_emails = []
        messages = []

        for addr in emails:
            try:
                good_emails.append(self.email.to_python(addr, state))
            except Invalid, e:
                messages.append(str(e))

        if messages:
            raise Invalid("; ".join(messages), value, state)
        else:
            return ", ".join(good_emails)
 def _validate_python(self, value, state):
     if value == 4:
         raise Invalid(self.message('custom', state, number='four'), value,
                       state)
 def _validate_other(self, value, state):
     if value == '3':
         raise Invalid(self.message('custom', state, number='three'), value,
                       state)
 def _convert_from_python(self, value, state):
     if value == 2:
         raise Invalid(self.message('custom', state, number='two'), value,
                       state)
     return str(value)
 def _convert_to_python(self, value, state):
     if value == '1':
         raise Invalid(self.message('custom', state, number='one'), value,
                       state)
     return int(value)
示例#12
0
 def raise_error_bad_url(self, value, state):
     msg = _('That is not a valid URL.')
     raise Invalid(msg, value, state)
示例#13
0
 def _to_python(self, value, state):
     dbsession = DBSession()
     if dbsession.query(User).filter(User.email == value).count() != 0:
         raise Invalid('That email address is already registered', value,
                       state)
     return value
示例#14
0
 def _to_python(self, value, state):
     if value != self.get_hash():
         msg = "Form token mismatch! Please try resubmitting the form."
         raise Invalid(msg, value, state)
     return None
示例#15
0
 def _to_python(self, value, state):
     """Parse a string and return a float or integer."""
     try:
         return format.parse_decimal(value)
     except ValueError:
         raise Invalid(self.message('badFormat', state), value, state)
示例#16
0
 def to_python(self, value, state=None):
     try:
         return super(MultipleSelection, self).to_python(value, state)
     except Invalid:
         raise Invalid(_("Please select at least a value"), value, state)