@view_config(renderer="templates/form.pt", name="edit")
@demonstrate("Edit Form")
def edit(self):
import datetime
class Mapping(colander.Schema):
name = colander.SchemaNode(
colander.String(), description="Content name"
)
date = colander.SchemaNode(
colander.Date(),
widget=deform.widget.DatePartsWidget(),
description="Content date",
)
class Schema(colander.Schema):
number = colander.SchemaNode(colander.Integer())
mapping = Mapping()
schema = Schema()
form = deform.Form(schema, buttons=("submit",))
# We don't need to supply all the values required by the schema
# for an initial rendering, only the ones the app actually has
# values for. Notice below that we don't pass the ``name``
# value specified by the ``Mapping`` schema.
appstruct = {
"number": 42,
"mapping": {"date": datetime.date(2010, 4, 9)},
}
return self.render_form(form, appstruct=appstruct)