Deserialize Multidict using Colander

93 views Asked by At

On a website I have a <select> element with multiple attribute like so:

<select value="name" multiple>
  <option value="willi">Willi</option>
  <option value="wonka">Wonka</option>
</select>

If both options are selected, then the Pyramid server’s view function receives the request object with a multidict instance:

 MultiDict([('name', 'willi'), ('name', 'wonka')])

Because I’ve been using Colander for data validation and deserialization, I wanted to write a schema for this instance… but after digging around the documentation I’m beginning to wonder if that’s at all possible?

So, how would I deserialize this particular multidict using Colander?

1

There are 1 answers

0
Michael Merickel On

I suspect you'll want to use something like request.POST.mixed() which will return a list for the name key if multiple values were sent (but not a list if just one value) combined with maybe a colander preparer to convert it to a list if it isn't already.