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 else static-deform by default), and configures a template search path (if one is specified by pyramid_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 named save, then save_success() will be called on successful validation or save_failure() will be called upon failure. An exception to this is when no such save_failure method is present; in this case, the fallback is failure`().

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 the deform.Field.render() of an instance of form_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).

buttons = ()

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 given e object (an instance of deform.exception.ValidationFailure) as the form key in a dict 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 to schema.

By default, this method returns a dict with request - the object passed to __init__(). The returned structure will be passed as keyword arguments to schema.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 an appstruct if appstruct() provides one. Otherwise, it is rendered without. Returns the rendered form as the form key in a dict 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.