9

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 !

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ascobol
  • 7,554
  • 7
  • 49
  • 70
  • Better ask on the Pylons list –  Jul 03 '11 at 15:27
  • 4
    @Sentinel - Why *better*? This is a totally good question for SO, as those on Django and other framework... What was the point you were trying to do? (Honest question, I'm just trying to understand the logic) – mac Jul 03 '11 at 15:44
  • @mac: if it's a good question, why don't you upvote it ? ;-) – ascobol Jul 03 '11 at 15:49
  • 1
    @ascobol - +1 because you asked for it, but since I don't know anything about pylons, it's difficult for me to tell if you did your research well before posting the question (maybe there are a trillions other identical questions phrased differently on SO?). – mac Jul 03 '11 at 15:53
  • 2
    @Sentinel: Mailing lists suck. They are often much slower than sites like SO, you often have to sign up first (and then receive mails about crap you don't care about), ... – ThiefMaster Jul 04 '11 at 08:29

1 Answers1

5

You might try "missing = colander.null".

Chris McDonough
  • 2,479
  • 18
  • 18