Must test also nmaxrecords :

    if nmaxrecords is None or nmaxrecords == '-1':
        limitby=0
    elif nminrecords:
        limitby=(int(nminrecords), int(nmaxrecords))
    else:
        limitby=(0, int(nmaxrecords))

On Thu, Oct 11, 2012 at 12:52 PM, Richard <ml.richard.vez...@gmail.com>wrote:

> Ok,
>
> In this case, I would test the startrecord :
>
>     if nmaxrecords == '-1':
>         limitby=0
>     elif nminrecords:
>         limitby=(int(nminrecords), int(nmaxrecords))
>     else:
>         limitby=(0, int(nmaxrecords))
>
> Since if it is not passed the vars will be empty and raise nonetype error.
>
> :)
>
> My eval(request.vars.limitby) was a pretty bad idea, because someone could
> have pass arbitrary web2py command by the url...
>
> Richard
>
> Le jeudi 11 octobre 2012 12:26:54 UTC-4, Niphlod a écrit :
>
>> I'd go for checking for howmanyrecord = -1 and in your controller
>>
>> if howmanyrecord == '-1':
>>      limitby = False
>> else:
>>      limitby = (int(startrecord), int(howmanyrecord ))
>>
>> return db(yourquery).select(limitby=l**imitby)
>>
>>
>>
>> On Thursday, October 11, 2012 6:13:55 PM UTC+2, Richard wrote:
>>>
>>> Hello,
>>>
>>> I have component tools, they serve to show table build from a query with
>>> redirect link. I place them in differents places in my app and depending of
>>> the place I would like to be able to pass max number of rows to the
>>> underling query used to build the table showed in the component. So I could
>>> do :
>>>
>>> {{=LOAD(c='dashboard_tools', f='tool1', *vars=dict(minrows=0,
>>> maxrows=10)*, extension='load', ajax=True)}}
>>>
>>> But if I would like to have all the records... What is the proper way??
>>>
>>> My first thought was to pass maxrows=0 or -1 than query should
>>> return all the records. But limitby it is not working like that.
>>>
>>> Then I realize that passing only one parameter to the limitby
>>> (limitby=0) would lead to what I want.
>>>
>>> Since
>>>
>>> db(db.table.id>0).select(db.**table.ALL, limitby=(0))
>>>
>>> Return all the records
>>>
>>> So I could just do that :
>>>
>>> {{=LOAD(c='dashboard_tools', f='tool1', *vars=dict(limitby=0)*,
>>> extension='load', ajax=True)}}
>>>
>>> or
>>>
>>> {{=LOAD(c='dashboard_tools', f='tool1', *vars=dict(limitby=(0,10))*,
>>> extension='load', ajax=True)}}
>>>
>>> But the later seems not working because request.vars.limitby is a
>>> string...
>>>
>>> This can easily be managed like this
>>>
>>> {{=LOAD(c='dashboard_tools', f='tool1', *vars=dict(limitby='(0,10)')*,
>>> extension='load', ajax=True)}}
>>>
>>> eval(request.vars.limitby)
>>>
>>> *But I am concerned about the security, should I??*
>>>
>>> Other solution could be to stick with minrows, maxrows and :
>>>
>>> if minrows or maxrows:
>>>     limitby=(int(request.vars.**minrows),int(request.vars.**maxrows)
>>> else:
>>>     limitby=int(request.vars.**minrows)
>>>
>>> Maybe the book should contain little more explanation about the use of
>>> limitby in context of URL and vars ?
>>>
>>> Thank you.
>>>
>>> Richard
>>>
>>  --
>
>
>
>

-- 



Reply via email to