Latest Version: 0.9.6.2

decorators

Pylons Decorators: jsonify, validate, REST, and Cache decorators


Functions

f jsonify(f) ...

Action decorator that formats output for JSON

Given a function that will return content, this decorator will turn the result into JSON, with a content-type of 'text/javascript' and output it.

f validate(schema=None, validators=None, form=None, variable_decode=False, dict_char='.', list_char='-', post_only=True, state=None, **htmlfill_kwargs) ...

Validate input either for a FormEncode schema, or individual validators

Given a form schema or dict of validators, validate will attempt to validate the schema or validator list.

If validation was succesfull, the valid result dict will be saved as self.form_result. Otherwise, the action will be re-run as if it was a GET, and the output will be filled by FormEncode's htmlfill to fill in the form field errors.

If you'd like validate to also check GET (query) variables (not GET requests!) during its validation, set the post_only keyword argument to False.

Warning

post_only applies to where the arguments to be validated come from. It does not restrict the form to only working with post, merely only checking POST vars.

Example:

1
2
3
4
5
6
7
8
9
class SomeController(BaseController):

    def create(self, id):
        return render('/myform.mako')

    @validate(schema=model.forms.myshema(), form='create')
    def update(self, id):
        # Do something with self.form_result
        pass

See the source for more information.

Top