Esempio n. 1
0
def is_string(v):
    """ checks that the value is an instance of basestring """
    if v is None:
        return
    msg = "must be a string"
    if not isinstance(v,basestring):
        raise validatish.Invalid(msg)
Esempio n. 2
0
 def __call__(self, v):
     if v['amount'] is not None and v['hours'] is None and v['days'] is None:
         return None
     if v['amount'] is None and v['hours'] is not None and v['days'] is None:
         return None
     if v['amount'] is None and v['hours'] is None and v['days'] is not None:
         return None
     else:
         msg = "Exactly one of amount, hours or days must be set."
         raise validatish.Invalid(msg)
Esempio n. 3
0
 def validate(self, value):
     """
     Validate the tuple's items and the tuple itself.
     """
     if value:
         if len(self.attrs) != len(value):
             raise Invalid({'': validatish.Invalid("Incorrect size")})
         for attr, item in zip(self.attrs, value):
             attr.validate(item)
     super(Tuple, self).validate(value)
Esempio n. 4
0
 def _test(self, schema, attr):
     ERROR_TEXT = '!!!WOOP!!!WOOP!!!WOOP!!!'
     form = formish.Form(schema,
                         errors={attr: validatish.Invalid(ERROR_TEXT)})
     html = form()
     element = BeautifulSoup(html).find(id='%s--field' %
                                        (attr.replace('.', '-'), ))
     div_error = element.find('div', {'class': 'error'})
     span_error = element.find('span', {'class': 'error'})
     assert div_error or span_error
     if div_error:
         assert div_error.string == ERROR_TEXT
     if span_error:
         assert span_error.string == ERROR_TEXT
Esempio n. 5
0
def _fix_website_validation_errors(form):
    # The websites field is a sequence but it uses a textarea widget, which
    # seems to confuse formish, because it's assuming you're using that widget
    # for a scalar.  (At least that's my best theory so far.)  As a work around,
    # go fishing in the form errors for website errors and move them up to the
    # level of the entire field rather than the level of a particular value.
    if 'websites' in form.errors:
        # Refuse to clobber a field level error message if one is set
        return

    errors = []
    for name in list(form.errors):
        if name.startswith('websites.'):
            error = form.errors[name]
            errors.append(str(error))
            del form.errors[name]
    if errors:
        form.errors['websites'] = validatish.Invalid('\n'.join(errors))
Esempio n. 6
0
def required(s):
    if not s:
        import validatish
        raise validatish.Invalid(s)
Esempio n. 7
0
 def fail(value):
     raise validatish.Invalid('fail')