I think I need a little breifing of the detect_record_change=True

What I thought :

form = SQLFORM.factory(...) # It is just a fake form to allow me to use the
web2py form utility to make possible a bulk review...

So I make a md5_hash of row md5_hash to get a sum_of_sum...

Now I want to take advantage of the detect_record_change to make sure
record displayed into SQLTABLE have not been update, delete or new record
inserted that could be caught by my query...

Here what I have so far :

Controller :

def select1():
    db.test1.virtualfields.append(v_f_s())
    rows = db(db.test1.id>0).select(db.test1.ALL)
    rows.colnames.append('test1.hmd5') # from brunon snipts...
    list_of_row_md5h = []
    for r in rows:
        list_of_row_md5h.append(r.hmd5)
    sum_of_sum = md5_hash('|'.join(str(i) for i in list_of_row_md5h))
    table = SQLTABLE(rows, columns=['test1.id
','test1.f1','test1.f2','test1.review','test1.hmd5'])
    form = SQLFORM.factory(Field('review_records', 'boolean',
requires=IS_NOT_EMPTY()))
    form._formkey = sum_of_sum* # does notting here...*
    form.process(detect_record_change=True)
    if form.record_changed:
        session.flash = 'one of the record have changed before you review
them, please review again carefully...'
        redirect(URL(request.application,c=request.controller,f='select1'))
    if form.accepted:
        for r in rows:
           db(db.test1.id == r.id).update(review='TRUE')
           response.flash = 'bunch_review_executed'
    elif form.errors:
        response.flash = 'form has errors'
    return dict(table=table, form=form)

model :

db.define_table('test1',
    Field('f1','string'),
    Field('f2','integer'),
    Field('review','boolean'))

from utils import md5_hash

class v_f_s(object):
    def hmd5(self):
        return md5_hash('|'.join(str(self.test1[k]) for k in
db.test1.fields()))

How can I detect record change if I overwrite the formkey value once the
form have been accepted??

Richard

On Wed, Dec 14, 2011 at 12:24 PM, Anthony <[email protected]> wrote:

> The _formkey is generated by form.accepts (or form.process), so after
> calling that, you can change it via:
>
> form.formkey = 'your_hash'
>
> Anthony
>
>
> On Wednesday, December 14, 2011 12:18:48 PM UTC-5, Richard wrote:
>
>> Hello Anthony,
>>
>> I am pretty near my goal...
>>
>> I can't find if I can replace SQLFORM.factory _formkey/value by my own
>> hash and if so... How can I do it??
>>
>> I try this without success :
>>
>> form = SQLFORM.factory(Field('review_**records', 'boolean',
>> requires=IS_NOT_EMPTY()),**hidden=dict(_formkey=sum_of_**sum))
>>
>> It add a new field _formkey...
>>
>> Thanks
>>
>> Richard
>>
>>
>> On Tue, Dec 13, 2011 at 4:38 PM, Anthony <[email protected]> wrote:
>>
>>> On Tuesday, December 13, 2011 4:33:38 PM UTC-5, Richard wrote:
>>>>
>>>> Hello Anthony,
>>>>
>>>> Since my "row" come from a query may I can do something like this
>>>> (pseudo code) :
>>>>
>>>> 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)).*
>>>> *se**lect\
>>>>         (db[request.args(0)].ALL, *HASH_FUNC(db[request.args(0)].ALL)*
>>>>  orderby=db.lotns_sample.**s**ample_code)
>>>>
>>>>
>>>> In SQL it is pretty common to use Alias for computed field on the
>>>> fly... I just don't know if web2py can handle it that way...
>>>>
>>>
>>> Maybe use a virtual field, which can be applied to a join:
>>> http://web2py.com/book/**default/chapter/06#Virtual-**Fields<http://web2py.com/book/default/chapter/06#Virtual-Fields>
>>>
>>>
>>
>>

Reply via email to