I redid the @validate decorator, because I hate it.
it seems to work, but needs some help.
i put it on pylonshq as a pastie here:
http://pylonshq.com/pasties/4fb8ce88c6d42b2ee048cf0ef0e678c1
to note:
- decorating with @osn_validate is mostly backwards compatible
- - the main difference is that there is a gatekeeper functionality ,
set true to default. the gatekeeper will cause an error if the form
doesn't process. the concept is to get around issues where post_only
could be true, but an arg like "submit=true" is sent via get and
dispatches to your form submit anyways.
- osn_validate wraps osn_form_validator and osn_form_reprint
- osn_form_validator does two takes:
- - returns True or False based on it being valid or not
- - sets up self.osn_form on your controller.
- - you can also submit 'params' to it, to validate outside of get/
post args
osn_form is a osn_FormResults object. it just stores the following
info:
- is_error
- is_parsed
- errors
- params
- results
why would we store that info ?
because then you can import osn_form_reprint into controllers and
then...
self.osn_form.errors['age']= 'yay custom errors throws!'
self.osn_form.errors['sex']= 'more than one!'
self.osn_form.errors['language']= 'now i can make fun websites
easier!'
return osn_form_reprint( self , 'print_function' )
a few other things i did:
- i changed "self" to "ControllerInstance" , because the term "self"
was confusing to me.
- osn_form is stashed as c. osn_form ; but the results & errors are
copied back to where @validate wants them too
- i created a ValidationStop exception to just stop validating when
needed. an earlier version of this used it extensively, now its
barely used, but still useful
i'm sure this could be improved upon a bit!