[web2py] Re: args(0) is always None??

2011-03-27 Thread pbreit
Yeah, it looks like the code didn't come through very well. Pastebin would 
be good or go to groups.google.com where you can paste it and format it as 
"Courier New" font.

I'd try to stay away from using 0 in your business logic. It might not 
always do what you expect since it can have different meanings in different 
contexts. The one place where you *do* use it is when checking the length of 
an object (ie if len(request.args(0))>0:). For example, to retrieve all rows 
in a table, you can do something like this: rows = db().select(db.
questionaire.ALL, orderby='')
*
*
Another tactic I would recommend is to get one component working well before 
integrating it with something else. You've got some complicated things going 
on such as appending to forms, checking IS_IN_SET against a query, and some 
complex query mashing in general.

For checking the form before it gets processed, "onvalidation" might 
work: http://web2py.com/book/default/chapter/07#onvalidation


[web2py] Re: args(0) is always None??

2011-03-27 Thread DenesL

The code is all messed up in the post above.
Could you repost to pastebin.com for example and copy the link here?.


On Mar 27, 8:09 pm, niknok  wrote:
> I have this function that displays several fields from two databases.
> but I couldn't get it to do the following:
>
> 1) the "previous question" button actually causes an error. how come
> my session.item_id is always zero when I thought I was passing an
> incrementing value session.item_id+1 .
>
> 2) when i select a value from the dropdown list get an error saying
> that I chose the wrong value
>
> 3) i am thinking of collecting the answers in an array so i can check
> the answers before storing them as a records in a database. how do i
> do that?
>
> i look forward to your suggestions to make this move forward.
>
> def quiz():
>         item_id =int(request.args(0) or 0)
>
>         if item_id == 0:
> False).select(orderby='')
>                 # Females = db(db.questionnaire.id>0 
> ).select(orderby='')
>                 print request.args(0), item_id, 'retrieving'
>                 query = db(db.questionnaire.id>0).select(orderby='')
>                 query_t = db(db.questionnaire_fil.id>0).select()
>
>         form = SQLFORM.factory(
>                 Field('default', 'text', writable=False, 
> default=query[item_id]
> ['dialog']),
>                 Field('locale', 'text', writable=False,
> default=query_t[int(query[item_id]['dialog_id']-1)]['dialog']),
>                 Field('answer', 'list:string',
>                         
> requires=IS_IN_SET(query_t[int(query[item_id]['dialog_id'])-1]
> ['choices'], zero=None, multiple=True)),
>                 _style='width:400px'
>                 )
>
>         form[0][-1][1].append(XML('  '))
>         form[0][-1][1].append(INPUT (_type='button',_value=T('Previous
> question'),
>                         
> _onclick="window.location='%s';"%URL(r=request,args=(item_id-1) or
> 0)))
>
>         if form.accepts(request.vars,session):
>                 if item_id<=len(query):
>                         response.flash= request.vars, item_id, request.args(0)
>                         URL(r=request,args=(item_id+1))
>                 else: URL(r=request, f='quiz_check')
>
>         return dict(form=form, item_id=item_id)