gavo.formal.form module

Form implementation and high-level renderers.

class gavo.formal.form.Action(callback, name, validate, label)[source]

Bases: object

Tracks an action that has been added to a form.

class gavo.formal.form.AddHelperMixin[source]

Bases: object

A mixin that provides methods for common uses of add(…).

class gavo.formal.form.Field(name, type, widgetFactory=None, label=None, description=None, cssClass=None, form=None, default=None)[source]

Bases: object

itemParent = None
property key
makeWidget()[source]
process(request, form, args, errors)[source]
setItemParent(itemParent)[source]
class gavo.formal.form.FieldFragment(field)[source]

Bases: CommonRenderers, Element

field(request, tag)[source]
hiddenLoader = <twisted.web._template_util.TagLoader object>
loader: Optional[ITemplateLoader] = <twisted.web._template_util.TagLoader object>
class gavo.formal.form.Form(callback=None)[source]

Bases: AddHelperMixin, object

actions = None
addAction(callback, name='submit', validate=True, label=None)[source]
addField(*a, **k)[source]
addGroup(*a, **k)[source]
callback = None
process(request)[source]
class gavo.formal.form.FormErrors[source]

Bases: object

add(error)[source]
getFieldError(name)[source]
getFormErrors()[source]
class gavo.formal.form.FormItems(itemParent)[source]

Bases: object

A managed collection of form items.

add(item)[source]
getItemByName(name)[source]
class gavo.formal.form.FormRenderer(original, *a, **k)[source]

Bases: CommonRenderers

loader = <twisted.web._template_util.TagLoader object>
render(request)[source]
class gavo.formal.form.FormsResourceBehaviour(**k)[source]

Bases: object

I provide the IResource behaviour needed to process and render a page containing a Form.

form(name)[source]
locateForm(request, name)[source]

Locate a form by name.

Initially, forms are located by looking for a form_<name> attribute in our parent. Once a form has been found, we cache it in request.

This ensures that the form that is located during form processing will be the same instance that is located when a form is rendered after validation failure.

runAction(request, formName)[source]
class gavo.formal.form.Group(name, label=None, description=None, cssClass=None, form=None)[source]

Bases: object

addField(*a, **k)[source]
addGroup(*a, **k)[source]
itemParent = None
property key
process(request, form, args, errors)[source]
setItemParent(itemParent)[source]
class gavo.formal.form.GroupFragment(group)[source]

Bases: Element

loader: Optional[ITemplateLoader] = <twisted.web._template_util.TagLoader object>
class gavo.formal.form.KnownForms[source]

Bases: dict

class gavo.formal.form.ResourceWithForm[source]

Bases: TemplatedPage

A t.w Resource with a template that has one or more forms.

To handle serious errors occurring during form processing, override the crash(failure, request) method. More benign errors are handled through form errors are and being rendered into the normal form.

By default, GET requests do not run actions. If your actions don’t change state, you should be ok with setting a class variable processOnGET, though.

crash(failure, request)[source]
form(name)[source]
formFactory(request, name)[source]
processOnGET = False
render(request, customCallback=None)[source]

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

gavo.formal.form.itemKey(item)[source]

Build the form item’s key. This currently always is the item name.