How to make file upload optional with Deform and Colander?

I would like to display a form containing a sequence of files representing different product images. File submission should be optional, so the form should be checked even if there are no files. How can i do this?

Here is the collaborator diagram I am using:

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 adding an β€œmissing” argument, for example:

 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 if this is the right way to do this ...

Thanks!

+8
python pyramid colander deform
source share
1 answer

You can try "missing = colander.null".

+4
source share

All Articles