Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyramid checkboxes

I'm just new to python and pyramid and I'm struggling with how to process the results of a form containing multiple checkboxes in Pyramid.

Here is an excerpt from my form:

<p tal:repeat="category categories">
    <input type="checkbox" name="selectedcategories" value="${category.id}"> ${category.name}<br/>
</p>

And here is how I am currently trying to iterate through and process the results:

selectedcategories=request.params['selectedcategories']    
for categoryid in selectedcategories:
        category = DBSession.query(Category).filter_by(id=categoryid).one()
        article.categories.append(category)

As you may have guessed, I'm only getting a maximum of one checkbox recognized no matter how many I select on the form. Django has an option to return the results as a list, but I can't seem to figure out how to do that with Pyramid.

like image 441
dusty909 Avatar asked Aug 04 '12 08:08

dusty909


1 Answers

request.params is a multidict. To retrieve multiple values, you can call its getall() method:

selectedcategories = request.params.getall("selectedcategories")
like image 142
Frédéric Hamidi Avatar answered Oct 07 '22 06:10

Frédéric Hamidi