API Documentation¶
-
pyramid_deform.
includeme
(config)¶ Provide useful configuration to a Pyramid
Configurator
instance.Currently, this hook will set up and register translation paths for Deform and Colander, add a static view for Deform resources (uses
pyramid_deform.static_path
from the Pyramid configuration if specified elsestatic-deform
by default), and configures a template search path (if one is specified bypyramid_deform.template_search_path
in your Pyramid configuration).
Form view¶
-
class
pyramid_deform.
FormView
(request)¶ Helper view for Deform forms for use with the Pyramid framework.
-
__call__
()¶ Prepares and render the form according to provided options.
Upon receiving a
POST
request, this method will validate the request against the form instance. After validation, this calls a method based upon the name of the button used for form submission and whether the validation succeeded or failed. If the button was namedsave
, thensave_success()
will be called on successful validation orsave_failure()
will be called upon failure. An exception to this is when no suchsave_failure
method is present; in this case, the fallback isfailure`()
.Returns a
dict
structure suitable for provision tog the given view. By default, this is the page template specified
-
appstruct
()¶ Returns an
appstruct
for form default values when rendered.By default, this method does nothing. Override this method in your derived class and return a suitable entity that can be used as an
appstruct
and passed to thedeform.Field.render()
of an instance ofform_class
.
-
before
(form)¶ Performs some processing on the
form
prior to rendering.By default, this method does nothing. Override this method in your derived class to modify the
form
. Your function will be executed immediately after instansiating the form instance in__call__()
(thus before obtaining widget resources, considering buttons, or rendering).
Tuple of buttons or strings to pass to the form instance. Override in your derived class.
-
failure
(e)¶ Default action upon form validation failure.
Returns the result of
render()
of the givene
object (an instance ofdeform.exception.ValidationFailure
) as theform
key in adict
structure.
-
form_class
¶ Class object of the type of form to be created. Defaults to using the standard
deform.form.Form
class.alias of
Form
-
form_options
= ()¶ Two-tuple of options to pass as keyword arguments when instantiating the form instance of
form_class
. Any options that can be passed to this class’__init__
can be provided here.
-
get_bind_data
()¶ Return a
dict
-like structure to bind toschema
.By default, this method returns a
dict
withrequest
- the object passed to__init__()
. The returned structure will be passed as keyword arguments toschema.bind()
.
-
schema
= None¶ Colander schema instance to be used to create the form instance. Provide your schema in your derived class.
-
show
(form)¶ Render the given form, with or without an
appstruct
context.The given
form
argument will be rendered with anappstruct
ifappstruct()
provides one. Otherwise, it is rendered without. Returns the rendered form as theform
key in adict
structure.
-
Other¶
-
class
pyramid_deform.
CSRFSchema
(*arg, **kw)¶ Schema base class which generates and validates a CSRF token automatically. You must use it like so:
from pyramid_deform import CSRFSchema import colander class MySchema(CSRFSchema): my_value = colander.SchemaNode(colander.String()) And in your application code, *bind* the schema, passing the request as a keyword argument: .. code-block:: python def aview(request): schema = MySchema().bind(request=request) In order for the CRSFSchema to work, you must configure a *session factory* in your Pyramid application.