If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Hello,

I'd like to filter the records returned based on which check boxes are selected by the user.

Here's the controller function:

def ebulletin():
    if request.vars.ht_tag_label == True:
        posts = db((db.post.ebulletin_approved==True) & (db.post.ht_tag==True)).select(orderby=~db.post.date_stamp)
        return dict(posts=posts)
    elif request.vars.y7_tag_label == True:
        posts = db((db.post.ebulletin_approved==True) & (db.post.y7_tag==True)).select(orderby=~db.post.date_stamp)
        return dict(posts=posts)
    else:
        posts = db(db.post.ebulletin_approved==True).select(orderby=~db.post.ht_tag|~db.post.date_stamp)
        return dict(posts=posts)
 
I haven't coded the rest of the function yet, I just want to get the thing working first. Here's the view:
 
<form id="filter_posts" name="filter_posts" method="post" action="ebulletin.html">
  <tr>
    <td width="10%"><strong>Filter<br />News</strong></td>
    <td width="6%">Head Teacher</td>
    <td width="4%" align="center"><input type="checkbox" name="ht_tag_label" id="ht_tag_label" /></td>
    <td width="6%">Senior Leaders</td>
    <td width="4%" align="center"><input type="checkbox" name="slt_tag_label" id="slt_tag_label" /></td>
    <td width="6%">Whole School</td>
    <td width="4%" align="center"><input type="checkbox" name="ws_tag_label" id="ws_tag_label" /></td>
    <td width="6%">Year 7</td>
    <td width="4%" align="center"><input type="checkbox" name="y7_tag_label" id="y7_tag_label" /></td>
    <td width="6%">Year 8</td>
    <td width="4%" align="center"><input type="checkbox" name="y8_tag_label" id="y8_tag_label" /></td>
    <td width="6%">Year 9</td>
    <td width="4%" align="center"><input type="checkbox" name="y9_tag_label" id="y9_tag_label" /></td>
    <td width="6%">Year 10</td>
    <td width="4%" align="center"><input type="checkbox" name="y10_tag_label" id="y10_tag_label" /></td>
    <td width="6%">Year 11</td>
    <td width="4%" align="center"><input type="checkbox" name="y11_tag_label" id="y11_tag_label" /></td>
    <td width="10%" align="right"><input type="submit" /></td>
  </tr>
  </form>
</table>
<br />
{{for post in posts:}}
 
The rest of the code is just html layout for the results.
 
What am I doing wrong?

 

Answers (1)

Comments (1)

  • Login to post



  • 0
    pang 9 years ago

    What am I doing wrong?

    You're writing at slices, which is a place to share a tip with the web2py comunity. You can ask this kind of question in the google group!
    smiley

Related content


Hosting graciously provided by:
Python Anywhere