I would like to render a form containing a sequence of files, representing different images of a product. Providing files should be facultative, so the form should validate even in the absence of files. How can I do this ?
Here is the colander schema I use:
import colander
import deform
from deform import Form
from deform import ValidationFailure
from deform.interfaces import FileUploadTempStore
tmpstore = FileUploadTempStore()
class Image(colander.Schema):
image = colander.SchemaNode(
deform.FileData(),
widget=deform.widget.FileUploadWidget(tmpstore)
)
class Images(colander.SequenceSchema):
images = Image()
class ProductSchema(colander.Schema):
completename = colander.SchemaNode(colander.String(), title="Complete Name")
description = colander.SchemaNode(colander.String(),
widget = deform.widget.TextAreaWidget())
images = Images()
schema = ProductSchema()
form = Form(schema, buttons=("submit", ))
I tried to add a 'missing' argument like:
image = colander.SchemaNode(
deform.FileData(),
missing = ???
widget=deform.widget.FileUploadWidget(tmpstore)
)
I think I get something functional when
missing={'filename': None, 'uid':None}
But I'm really not sure it's the correct way to do it...
Thanks !
You might try "missing = colander.null".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With