API Reference¶
Forms¶
- class pyramid_uniform.State(request)[source]¶
A relatively simple state object for the schema being validated to use, with a reference to the request being validated.
- class pyramid_uniform.Form(request, schema, method='POST', skip_csrf=False)[source]¶
Represents a set of fields (GET or POST parameters) to be validated using a FormEncode schema.
Parameters: - request (WebOb.Request) – The web request containing data to be validated
- schema (FormEncode.Schema) – The schema to validate against
- method (str) – HTTP request method that this form expects: GET or POST
- assert_valid(**kw)[source]¶
Assert that this form is valid, the request method is appropriate, and the CSRF check passes (unless it is explicitly skipped).
- bind(obj)[source]¶
Bind the data from this form to an object: that is, try to set attributes on the client corresponding to the keys present in the validated data. The object can be a template object, SQLAlchemy object, etc.
If any value in the data is a list or another dictionary, recurse with that key.
Private attributes, which is anything that is prefixed with _, will be skipped.
Once done, return the object.
- data[source]¶
Once the form has been validated, contains the results of that validation as a dict.
Raises FormNotValidated: if the form has not yet been validated
- method_allowed[source]¶
Is the method that was used to submit this form allowed?
If this form doesn’t have a request method set (i.e., if it was explicitly set to None), any method is valid. Otherwise, the method of the form submission must match the method required by this form.
- validate(skip_csrf=False, assert_valid=False)[source]¶
Validate a form submission.
When assert_valid is False (the default), a bool will be returned to indicate whether the form was valid. (Note: this isn’t strictly true–a missing or bad CSRF token will result in a immediate 400 Bad Request response).
When assert_valid is True, certain conditions will be asserted. When an assertion fails, an AssertionError will be raised.
Parameters: - skip_csrf (bool) – if True, bypass the CSRF check
- assert_valid (bool) – if True, assert validity instead of returning status
Rendering¶
- class pyramid_uniform.Renderer(data, errors, name_prefix='', id_prefix='')[source]¶
- checkbox(name, value='1', checked=False, label=None, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a checkbox tag.
- file(name, value=None, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a file input tag.
Return a hidden input tag.
- password(name, value=None, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a password input tag.
- select(name, selected_values, options, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a select tag.
- submit(name=None, value=None, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a submit button tag.
- text(name, value=None, id=<class 'webhelpers2.misc.NotGiven'>, **attrs)[source]¶
Return a text input tag.
- class pyramid_uniform.FormRenderer(form, csrf_field='_authentication_token', name_prefix='', id_prefix='')[source]¶
Bases: pyramid_uniform.Renderer
Wraps a form to provide HTML rendering capability.
Exceptions¶
- exception pyramid_uniform.FormError(*args, **kw)[source]¶
Bases: exceptions.Exception
Superclass for form-related errors.
- exception pyramid_uniform.FormInvalid(*args, **kw)[source]¶
Bases: pyramid_uniform.FormError
Raised when form data is used but the form is not valid.
- exception pyramid_uniform.FormNotValidated(*args, **kw)[source]¶
Bases: pyramid_uniform.FormError
Raised when form data is used before form has been validated: for example, when Form.bind() is called.