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, **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
appstruct
as a set of default values and returns the HTML string.appstruct
is typically a dictionary of application values matching the schema used by this form, orcolander.null
to render all defaults. If it is omitted, the rendering will use theappstruct
passed 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
readonly
keyword 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.
-
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=u'Body', widget=RichTextWidget(), missing=u'', ) class DocumentEditForm(EditFormView): schema_factory = DocumentSchema
-
before
(form)[source]¶ Performs some processing on the
form
prior 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 = u'Document'
-
class
kotti.views.form.
CommaSeparatedListWidget
(**kw)[source]¶ -
serialize
(field, cstruct, readonly=False)[source]¶ The
serialize
method 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.serialize
should return the HTML rendering: the result of this method should always be a string containing HTML. Thefield
argument is the field object to which this widget is attached. The**kw
argument allows a caller to pass named arguments that might be used to influence individual widget renderings.
-
deserialize
(field, pstruct)[source]¶ The
deserialize
method of a widget must deserialize a pstruct value to a cstruct value and return the cstruct value. Thepstruct
argument is a value resulting from theparse
method of the Peppercorn package. Thefield
argument is the field object to which this widget is attached.
-