There are two callbacks: onvalidation and onaccept. They are executed
before and after the record is updated by the form submission. If you alter
the record on validation, it gets overwritten when the form is accepted.
Not sure why adding rows=... fixes the problem. Anyway you can replace your
code with:
def checkout_cc():
from gluon.dal import Expression
TOKEN='xxxxcd7358801fd5db53d74b03xxxx8b7b97a6c4'
Order.CCnr_secure.compute = \
lambda row, token=TOKEN, oid: \
Expression(db,"AES_ENCRYPT('%s','%s')" % (token,oid))
form=SQLFORM(Order, record=record, fields=fields, keepvalues=True,
showid=False,
formstyle='divs', submit_button=T('Continue'))
if form.process(keepvalues=True).accepted:
response.flash = T('Payment Information accepted')
On Wednesday, 26 September 2012 19:09:50 UTC-5, Adi wrote:
>
>
> My apology if a description of the problem is not concise enough. I am
> updating record during onvalidaiton process, and this worked until Sep 17.
> Anything is possible, but I don't remember changing any code in this area.
>
> When I run the same SQL statement manually, or from a test procedure,
> everything works fine, but not when it's executed through SQLFORM
> onvalidation process. I tried adding db.commit() and that didn't help,
> either.
>
> Finally, I added following query at the end, and then record got updated:
> row = db(Order.id==session.order_id).select().first()
>
> My problem seems to be solved for now, but not sure what is a real cause
> of the problem, and if something needs correction in executesql?
>
> Simplified code:
>
> def db_encrypt_cc(tbl=None, cc=None, id=None):
> TOKEN='xxxxcd7358801fd5db53d74b03xxxx8b7b97a6c4'
> sql = "UPDATE %s SET CCnr_secure = AES_ENCRYPT('%s', '%s') WHERE
> id=%s" % (tbl, cc, TOKEN, session.order_id)
> # when executed, this statement is correct, but no value gets updated
> in the table: UPDATE order SET CCnr_secure =
> AES_ENCRYPT('4111111111111111', 'xxxxcd7358801fd5db53d74b03xxxx8b7b97a6c4')
> WHERE id=10423
> db.executesql(sql)
> # added code bellow and only then record got updated
> row = db(Order.id==session.order_id).select().first()
> return
>
> def cc_validation(form):
> form.vars.CCnr_secure = db_encrypt_cc("order", form.vars.CCnr)
> return
>
> def checkout_cc():
> form=SQLFORM(Order, record=record, fields=fields, keepvalues=True,showid
> =False,
> formstyle='divs', submit_button=T('Continue'))
>
> if form.process(keepvalues=True, onvalidation=cc_validation).accepted:
> response.flash = T('Payment Information accepted')
>
>
>
>
>
--