Using this quick test
class Human(orm.Document):
_db = "test"
_collection = "humans"
human_id = field.AutoIncrement(collection="human")
name = field.Char(required=True, min=2, max=25)
class PersonForm(widget.Form):
_action = '/save_person'
_fields = ["human_id", "name"]
_id = "css_id"
_class= "css_class"
human_id = widget.Input(label="ID")
name = widget.Input(label="Name")
submit = {
"name":"Megatron",
"human_id":"6789",
}
human =Human()
human.name = "voltron"
human.human_id = "1234"
empty_form = PersonForm()
obj_form = PersonForm(object=human)
data_form = PersonForm(data=submit)
form = PersonForm(object=human, data=submit)
print
print "empty_form: ", empty_form.render()
print
print "obj_form: ", obj_form.render()
print
print "data_form: ", data_form.render()
print
print "form: ", form.render()
try:
form.validate()
except orm.DocumentException as e:
for f in form:
if f.errors:
print
f.name
if f.description: print f.description
print f.errors
print form.errors
print e.errors
else:
for f in form:
print f.render()
The result is:
empty_form: <form id='css_id' class='' name='' action='/save_person'
method='POST' type='multipart/form'><label for='human_id'>ID</
label><input type='text' id='id_human_id' name='human_id' value='None'
class='' /><label for='name'>Name</label><input type='text'
id='id_name' name='name' value='None' class='' /><input type='submit'
value='submit' /></form>
obj_form: <form id='css_id' class='' name='' action='/save_person'
method='POST' type='multipart/form'><label for='human_id'>ID</
label><input type='text' id='id_human_id' name='human_id' value='1234'
class='' /><label for='name'>Name</label><input type='text'
id='id_name' name='name' value='voltron' class='' /><input
type='submit' value='submit' /></form>
data_form: <form id='css_id' class='' name='' action='/save_person'
method='POST' type='multipart/form'><label for='human_id'>ID</
label><input type='text' id='id_human_id' name='human_id' value='None'
class='' /><label for='name'>Name</label><input type='text'
id='id_name' name='name' value='None' class='' /><input type='submit'
value='submit' /></form>
form: <form id='css_id' class='' name='' action='/save_person'
method='POST' type='multipart/form'><label for='human_id'>ID</
label><input type='text' id='id_human_id' name='human_id' value='1234'
class='' /><label for='name'>Name</label><input type='text'
id='id_name' name='name' value='voltron' class='' /><input
type='submit' value='submit' /></form>
<input type='text' id='id_human_id' name='human_id' value='6789'
class='' />
<input type='text' id='id_name' name='name' value='Megatron'
class='' />
So can I infer that the correct way to pre-fill a form is by using an
instantiated object and not just by passing data to the data attribute
of a form?