accpets takes two arguments
onvalidation=lambda form: None
onaccept=lambda form: None
onvalidation is run after validation before insert/update/delete
onaccept is done after insert/update/delete before redirection
It it technically possible to make onaccept point to a function that
does some checks and then eventuall calls db.rollback(). I
definitively advice against that. I think you constraints must be
checked before insert/update/delete. That is what onvalidation is for.
You validation takes the form and if you want to block the subsequent
insert/update/delete simply add an error to form.errors explaining the
problem. Example:
def algorithm(form):
if form.vars.a!=form.vars.b:
form.errors.b='should be the same as a"
form.accepts(request.vars,onvalidation=lambda form: algorithm(form))
On Jun 6, 5:52 pm, weheh <[email protected]> wrote:
> I'm doing the following:
> if form.accepts(request.vars,session,onvalidation=my_val):
> session.flash='success'
> redirect(URL(r=request,f='newpage'))
> elif form.errors:
> response.flash='error'
>
> I'm wondering if the data are committed to the db before my_val gets
> executed or only afterwards? In other words, if my_val does a db
> query, will it find already in the db the data from the form?
>
> If no, what if the form acceptance depends on checking the interaction
> between the data already in the db and data on the form?
>
> In essence, I want to write the form data to the db, run an algo, then
> decide whether to rollback the db. I think I'm really close to the
> answer, but I'm not sure what the right way is to do this. Anyone have
> a simple example?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---