Thanks for the tips Anthony...

Here an other test I made :

def bulk_update():
    rows = db((db.lotns_lot_number.id == request.args(1))&\
        (db.lotns_sample.lot_number_id == db.lotns_lot_number.id)&\
        (db[request.args(0)].sample_id ==
db.lotns_sample.sample_id)).select\
        (db[request.args(0)].ALL, orderby=db.lotns_sample.sample_code)

    not_to_show = ['input_date', 'data_grade', 'valid', 'reviewed', \
        'reviewed_by', 'revision_date', 'revision_comment', 'approved', \
        'approval_date', 'approved_by', 'approval_comment',
'last_action_by', \
        'sdate', 'update_record', 'delete_record']

    form = SQLFORM.factory(*[Field(f+'_%s'%r.id, default=r[f]) for r in
rows for f in r if f not in not_to_show])

    form.process(detect_record_change=True)
    if form.record_changed:

redirect(URL(request.application,c=request.controller,f='bulk_update',args=(request.args(0),request.args(1))))
        session.flash = T('form have changed between the time you edited
and submitted it, please have a look on the data again')
    elif form.accepted:
#        for key,value in form.vars.items():
#           db(db[request.args(0)].id==key[3:]).update(reviewed_by = 1) #
HERE I NEED TO IMPROVE...
        session.flash = T('form accepted').capitalize()
    else:
        response.flash = T('please correct the form')
    return dict(form=form)


What I would like to have that is not actually possible I think is a way to
"detect_record_change" with SQLFORM.factory...

Do you have any idea how I could achieve that?

Thanks

Richard


On Mon, Dec 12, 2011 at 5:52 PM, Anthony <[email protected]> wrote:

>     forms = []
>>     flag = 0
>>     for i in rows:
>>
>
> Python tip -- instead of the above, try:
>
> for flag, i in enumerate(rows):
>
>
>>         forms.append(SQLFORM(db[**request.args(0)],
>> i[request.args(0)].id))
>>
>
> It looks like your rows are actually the result of a multi-table join, so
> you might need to use SQLFORM.factory -- see
> http://web2py.com/book/default/chapter/07#One-form-for-multiple-tables.
>
>
>> {{for i in range(0,len(forms)):}}
>> {{=forms[i]}}
>>
>
> Another Python tip:
>
> {{for form in forms:}}
> {{=form}}
>
>
>
>> I am confuse and I am not sure if my controller can works independently
>> with each form embeded into forms the way I wrote my controller function...
>> What's the way you were telling me to do??
>>
>
> At this point, I'm a bit confused too. :-)  Maybe consider putting each
> form in a separate LOAD component -- see
> http://web2py.com/book/default/chapter/13#Components.
>
>>
>> PS.: Is there any way I can make a multiple lines update with SQLFORM or
>> .grid or .smartgrid??
>>
>
> I don't think so.
>
> Anthony
>

Reply via email to