is it faster to create a list of Field objects and use SQLFORM.factory()?

On Thursday, May 31, 2012 1:38:58 AM UTC-7, DanielB wrote:
>
> Ok this is the form.insert way:
>
> form = SQLFORM(DAL(None).define_table('empty'), table_name 
> = 'userEditNetAccess')
>
> form.custom.widget.nets = [ ]
> form.custom.label.nets = [ ]
>
> for net in nets:
>         element = INPUT(_name=net.name + str(net.id), value=net.checked, 
> _type='checkbox')
>         
>         form[0].insert(-1,element)
>         form.custom.label.nets.append(net.name)
>         form.custom.widget.nets.append(element)
>
> and then just go through the list of nets in the view with:
> {{for net in form.custom.widget.nets:}}
>     {{=net}}
> etc.
>
> the faster but uglier way:
> Just send the net list to the view and in the view:
> {{for sitenet in sitenets:}}
>     {{=INPUT(_type='checkbox', _name='sitenet_%i' % sitenet.id, 
> _value='on', _checked=sitenet.checked)}}
>     {{=sitenet.name}}
>
> This requires more work with going through request.vars of course to 
> handle the form submission
>
> Den onsdagen den 30:e maj 2012 kl. 15:40:46 UTC+2 skrev Anthony:
>>
>> I think form.insert just does a regular Python list insertion (plus two 
>> other trivial function calls). Can you show the form.insert code as well as 
>> your alternative list code?
>>
>> Anthony
>>
>> On Wednesday, May 30, 2012 8:12:39 AM UTC-4, DanielB wrote:
>>>
>>> Hi,
>>>
>>> I have a custom form that has a dynamic size with a for-loop that 
>>> inserts checkboxes into the form. 
>>> This works fine in small numbers, but when I increase the number of 
>>> checkboxes inserted I noticed the page takes longer and longer to load. 
>>> (obviously it's going to take longer but it's not linear)
>>>
>>> It seems that the form.insert code loops through all previous components 
>>> as well, is this by design and needed?
>>>
>>> If I don't use the form.insert and just use a list that I handle myself 
>>> it's much faster, but uglier and more code than if I could use form.insert.
>>>
>>> thankful for answers
>>>
>>> /Daniel
>>>
>>

Reply via email to