kotti.views.form¶
Form related base views from which you can inherit.
Inheritance Diagram¶
- class kotti.views.form.Form(schema, action='', method='POST', buttons=(), formid='deform', use_ajax=False, ajax_options='{}', autocomplete=None, focus='on', **kw)[source]¶
A deform Form that allows ‘appstruct’ to be set on the instance.
- render(appstruct=None, readonly=False)[source]¶
Render the field (or form) to HTML using
appstructas a set of default values and returns the HTML string.appstructis typically a dictionary of application values matching the schema used by this form, orcolander.nullto render all defaults. If it is omitted, the rendering will use theappstructpassed to the constructor.Calling this method passing an appstruct is the same as calling:
cstruct = form.set_appstruct(appstruct) form.serialize(cstruct, **kw)
Calling this method without passing an appstruct is the same as calling:
cstruct = form.cstruct form.serialize(cstruct, **kw)
See the documentation for
colander.SchemaNode.serialize()anddeform.widget.Widget.serialize().Note
Deform versions before 0.9.8 only accepted a
readonlykeyword argument to this function. Version 0.9.8 and later accept arbitrary keyword arguments.
- class kotti.views.form.BaseFormView(context, request, **kwargs)[source]¶
A basic view for forms with save and cancel buttons.
- buttons = (<deform.form.Button object>, <deform.form.Button object>)¶
Tuple of buttons or strings to pass to the form instance. Override in your derived class.
- class kotti.views.form.EditFormView(context, request, **kwargs)[source]¶
A base form for content editing purposes.
Set self.schema_factory to the context’s schema. Values of fields in this schema will be set as attributes on the context. An example:
import colander from deform.widget import RichTextWidget from kotti.edit.content import ContentSchema from kotti.edit.content import EditFormView class DocumentSchema(ContentSchema): body = colander.SchemaNode( colander.String(), title='Body', widget=RichTextWidget(), missing='', ) class DocumentEditForm(EditFormView): schema_factory = DocumentSchema
- before(form)[source]¶
Performs some processing on the
formprior to rendering.By default, this method does nothing. Override this method in your dervived 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).
- class kotti.views.form.AddFormView(context, request, **kwargs)[source]¶
A base form for content adding purposes.
Set self.schema_factory as with EditFormView. Also set item_type to your model class. An example:
class DocumentAddForm(AddFormView): schema_factory = DocumentSchema add = Document item_type = 'Document'
- class kotti.views.form.CommaSeparatedListWidget(template=None, **kw)[source]¶
- serialize(field, cstruct, readonly=False)[source]¶
The
serializemethod of a widget must serialize a cstruct value to an HTML rendering. A cstruct value is the value which results from a Colander schema serialization for the schema node associated with this widget.serializeshould return the HTML rendering: the result of this method should always be a string containing HTML. Thefieldargument is the field object to which this widget is attached. The**kwargument allows a caller to pass named arguments that might be used to influence individual widget renderings.
- static deserialize(field, pstruct)[source]¶
The
deserializemethod of a widget must deserialize a pstruct value to a cstruct value and return the cstruct value. Thepstructargument is a value resulting from theparsemethod of the Peppercorn package. Thefieldargument is the field object to which this widget is attached.