pylons.decorators – Decorators¶
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 ‘application/json’ and output it.
validate(schema=None, validators=None, form=None, variable_decode=False, dict_char='.', list_char='-', post_only=True, state=None, on_get=False, **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 successful, 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.
- Refers to a FormEncode Schema object to use during validation.
- Method used to display the form, which will be used to get the HTML representation of the form for error filling.
- Boolean to indicate whether FormEncode’s variable decode function should be run on the form input before validation.
- Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a dict. This option is only applicable when used with variable_decode=True.
- Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a list. This option is only applicable when used with variable_decode=True.
Boolean that indicates whether or not GET (query) variables should be included during validation.
post_onlyapplies 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.
- Passed through to FormEncode for use in validators that utilize a state object.
- Whether to validate on GET requests. By default only POST requests are validated.
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