I believe the function definition :
def get_onrp(npa, lns, npc=0):
does set the value of npc to 0 if the argument is not passed to the 
function call.

On Saturday, January 11, 2014 10:56:56 AM UTC+1, zee wrote:
>
> Hi,
>
> First post here, so thanks in advance for any help provided.
>
> I have a sub-routine in my main function of a a controller that looks like 
> this :
>
> if form.vars.npc:
>             pass
>         else:
>             form.vars.npc = 0
>         onrp_row = db(
>             (db.npa.npa==form.vars.npa) & 
>             (db.npa.loc_name_short==form.vars.lns) & 
>             (db.npa.npa_complement==form.vars.npc)
>             ).select(db.npa.id)
>         onrp_id=onrp_row[0].id
>
> Essentially, I use this to update a record I just inserted in the db with 
> a foreign primary key from an external data source. I need to keep this 
> reference for data consistency purposes in case the external source is 
> modified.
>
> This sub-routine behaves as expected.
>
> My problem is that I am trying to make a helper function out of this 
> sub-routine. I have extracted it from the index() function and my 
> controller now looks like this :
>
> def get_onrp(npa, lns, npc=0):
>     
> id=db((db.npa.npa==npa)&(db.npa.loc_name_short==lns)&(db.npa.npa_complement==npc)).select(
> db.npa.id)
>     if id:
>         return id[0].id
>     else:
>         return 0
>
> def index():
>     # SQLFORM.factory here
>
>     onrp_id = get_onrp(form.vars.npa, form.vars.lns, form.vars.npc)
>
>     # rest of controller logic here
>
> Now, the get_onrp function systematically returns 0, i.e. the db query 
> returns no rows.
>
> I have played around in the web2py interactive shell and defining the 
> function works as expected as well. 
>
> Any suggestions ?
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to