On Wednesday, October 15, 2014 8:05:57 PM UTC-4, LoveWeb2py wrote:
>
> Hi Anthony,
>
> I think that part is correct.
>

In your original code, the inner loop looped over correct_questions, but in 
the menu items, you did not reference the correct_questions item and 
instead referenced the question item from the outer loop -- that is why you 
saw the same menu item repeated multiple times.
 

> I've modified the code to do check if the question was answered correctly 
> in the controller and append the question id to a list. Still not 
> working... here is my controller:
>
>
> def questions_for_people():
>     correctList = []
>     correct_questions = db((db.questions_answered.correct=="on") & 
> (db.questions_answered.answered_by==auth.user.id)).select(db.questions_answered.ALL,
>  
> groupby=db.questions_answered.question, distinct=True).as_dict()
>

Why use .as_dict()? If you leave it as a Rows object, you can refer to 
row.question instead of having to do correct_questions[row]['question'].

Also, what is all_questions? Do they come from another db table, and if so, 
is it linked to db.questions_answered? Perhaps you could just do a single 
db query (via a join) to get the data you need.

            <ul>
>                     {{for question in all_questions:}}
>                     {{if question['diff_level']==100 and question['id'] 
> not in correctList:}}
>                 
>                     <li class="padded"><a href="{{=URL('challenges', 
> vars={'chal':question['id']})}}">{{=question['title']}} 
> ({{=question['points']}} pts) </a></li>
>                 {{pass}}
>                     {{else:}}
>                 {{if question['diff_level']==100 and question['id'] in 
> correctList:}}
>                 <li class="padded"><i class="fa fa-check icon-small"></i> 
> <a href="{{=URL('challenges', vars={'chal':question['id']})}}", 
> style="color:gray;">{{=question['title']}} ({{=question['points']}} pts) 
> </a></li>
>                 {{pass}}
>                 {{pass}}
>
> when I run this nothing returns back to my menu... 
>

If nothing returns, then presumable question['diff_level'] never equals 
100, as both if statements include that condition. Also, rather than 
nesting the second if inside an else, you can simply use an elif.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to