Thanks heaps Anthony. I'll give it a bash.

I had a look at the source for validate_and_update/insert and it
appears that it doesn't take the onvalidation parameter that SQLFORM
does. I guess I can apply the onvalidation method on its own and then
look for form.errors.

The form.accepts without a session is also a very good tip.

Cheers,
Stoyan.

On Aug 19, 10:25 pm, Anthony <[email protected]> wrote:
> Actually, you don't need to use SQLFORM at all to take advantage of
> validation. Instead, you can do:
>
> db.table.validate_and_insert(...)   # to insert new record
>
> or
>
> db(query).validate_and_update(...)  # to update an existing record
>
> (Note, the above is not in the book yet.)
>
> Also, if you want to use form.accepts but don't want it to save or check the
> unique _formkey in session, then just don't pass session to accepts():
>
> form.accepts(request.vars)  # notice no 'session'
>
> Anthony
>
>
>
>
>
>
>
> On Friday, August 19, 2011 8:46:57 AM UTC-4, stoyan wrote:
> > Dear fellow w2peers, I would like to make use of the db validators
> > through an sqlform, but without having user interaction. Code speaks
> > best:
>
> > logs = [ ]
> > for line in file('my_input_file.txt').readlines():
> >     name,age = line.split(',')
> >     form = SQLFORM(db.person)
> >     request.vars.name = name
> >     request.vars.age = age
> >     if form.accepts(request.vars, session,
> > onvalidate=validate_person):
> >         logs.append('record updated')
> >     elif form.errors:
> >         logs.append('errors in form')
> >     else:
> >         logs.append("I keep ending up here each time I call this
> > controller")
> > return dict(logs='</br>'.join(logs))
>
> > I also tried the following and got the same result as above:
> > ...
> > form.vars.name = name
> > form.vars.age = age
> > if form.accepts(form.vars, ...
>
> > My wild guess is that SQLFORM does not allow this because of security
> > concerns: the form's hidden fields do not match the session. Is there
> > a way around this?
>
> > My requirement is to be able to process the input file and populate/
> > update the persons table accordingly while validating the input
> > parameters with the table's validators and the form's onvalidate
> > method. All of this is done in one go from a single controller.
>
> > Any help/recommendations will be greatly appreciated.
>
> > Thanks,
> > Stoyan.

Reply via email to