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?
I suspect you'll want to use something like
request.POST.mixed()
which will return a list for thename
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.