[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Massimo Di Pierro
oops. right

def update_mytable():
record=request.args[0]
form=SQLFORM(db.timbrata,
 record, deletable=False)
form.process(onsuccess=lambda form: ( \
auth.archive(form),
form.record_id and
db(db.mytable.id==form.record_id).update(field2='option2')))
return dict (form=form)

On Nov 26, 1:17 pm, Anthony  wrote:
> If using form.process(), I think the arg would be 'onsuccess', not
> 'onaccept'.
>
> Anthony
>
>
>
>
>
>
>
> On Saturday, November 26, 2011 12:50:41 PM UTC-5, Massimo Di Pierro wrote:
>
> > I THINK YOU WANT:
>
> > def update_mytable():
> >     record=request.args[0]
> >     form=SQLFORM(db.timbrata,
> >                      record, deletable=False)
> >     form.process(onaccept=lambda form: ( \
> >             auth.archive(form),
> >             form.record_id and
> > db(db.mytable.id==form.record_id).update(field2='option2')))
> >     return dict (form=form)
>
> > On Nov 26, 10:40 am, Rocco De Marco  wrote:
> > > Hi all, I'm a fresh newbie using w2p.
> > > I would hope my question is not so stupid, but I've spended a lot of
> > > time trying to resolve myself, without success...
>
> > > I've this model:
>
> > > db.define_table('mytable',
> > >    Field('field1','string'),
> > >    Field('field2'))
> > > db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])
>
> > > I've already a created record with field2=option1
> > > I want to create a form where users can change the field1 value, but
> > > the field2 value should be automatically setted to option2 only if the
> > > record has been updated.
>
> > > I tried with:
>
> > > def update_mytable():
> > >     record=request.args[0]
> > >     form=SQLFORM(db.timbrata,
> > >                      record,
> > >                      onaccept=auth.archive,
>
> > > onupdate=db(db.mytable.id==record).update(field2='option2'),
> > >                      deletable=False)
> > >     return dict (form=form)
>
> > > But the filed2 is updated just when the form is showed, not, as I
> > > expected, after an update.
> > > Maybe I took a wrong way, someone could help?
>
> > > Regards, Rocco


[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Anthony
If using form.process(), I think the arg would be 'onsuccess', not 
'onaccept'.

Anthony

On Saturday, November 26, 2011 12:50:41 PM UTC-5, Massimo Di Pierro wrote:
>
> I THINK YOU WANT:
>
> def update_mytable():
> record=request.args[0]
> form=SQLFORM(db.timbrata,
>  record, deletable=False)
> form.process(onaccept=lambda form: ( \
> auth.archive(form),
> form.record_id and
> db(db.mytable.id==form.record_id).update(field2='option2')))
> return dict (form=form)
>
> On Nov 26, 10:40 am, Rocco De Marco  wrote:
> > Hi all, I'm a fresh newbie using w2p.
> > I would hope my question is not so stupid, but I've spended a lot of
> > time trying to resolve myself, without success...
> >
> > I've this model:
> >
> > db.define_table('mytable',
> >Field('field1','string'),
> >Field('field2'))
> > db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])
> >
> > I've already a created record with field2=option1
> > I want to create a form where users can change the field1 value, but
> > the field2 value should be automatically setted to option2 only if the
> > record has been updated.
> >
> > I tried with:
> >
> > def update_mytable():
> > record=request.args[0]
> > form=SQLFORM(db.timbrata,
> >  record,
> >  onaccept=auth.archive,
> >
> > onupdate=db(db.mytable.id==record).update(field2='option2'),
> >  deletable=False)
> > return dict (form=form)
> >
> > But the filed2 is updated just when the form is showed, not, as I
> > expected, after an update.
> > Maybe I took a wrong way, someone could help?
> >
> > Regards, Rocco
>
>

[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Rocco De Marco


On 26 Nov, 18:50, Massimo Di Pierro 
wrote:
> I THINK YOU WANT:
>
> def update_mytable():
>     record=request.args[0]
>     form=SQLFORM(db.timbrata,
>                      record, deletable=False)
>     form.process(onaccept=lambda form: ( \
>             auth.archive(form),
>             form.record_id and
> db(db.mytable.id==form.record_id).update(field2='option2')))
>     return dict (form=form)

Massimo, many thanks. Now is clear.










[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Massimo Di Pierro
I THINK YOU WANT:

def update_mytable():
record=request.args[0]
form=SQLFORM(db.timbrata,
 record, deletable=False)
form.process(onaccept=lambda form: ( \
auth.archive(form),
form.record_id and
db(db.mytable.id==form.record_id).update(field2='option2')))
return dict (form=form)

On Nov 26, 10:40 am, Rocco De Marco  wrote:
> Hi all, I'm a fresh newbie using w2p.
> I would hope my question is not so stupid, but I've spended a lot of
> time trying to resolve myself, without success...
>
> I've this model:
>
> db.define_table('mytable',
>    Field('field1','string'),
>    Field('field2'))
> db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])
>
> I've already a created record with field2=option1
> I want to create a form where users can change the field1 value, but
> the field2 value should be automatically setted to option2 only if the
> record has been updated.
>
> I tried with:
>
> def update_mytable():
>     record=request.args[0]
>     form=SQLFORM(db.timbrata,
>                      record,
>                      onaccept=auth.archive,
>
> onupdate=db(db.mytable.id==record).update(field2='option2'),
>                      deletable=False)
>     return dict (form=form)
>
> But the filed2 is updated just when the form is showed, not, as I
> expected, after an update.
> Maybe I took a wrong way, someone could help?
>
> Regards, Rocco


[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Rocco De Marco


On 26 Nov, 18:06, Anthony  wrote:
> On Saturday, November 26, 2011 11:40:27 AM UTC-5, Rocco De Marco wrote:
>
> > db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])
>
> I think you want:
>
> IS_IN_SET(['option1', 'option2'])
>

Yes, it is a my mistake...

> > def update_mytable():
>
> >     record=request.args[0]
> >     form=SQLFORM(db.timbrata,
> >                      record,
> >                      onaccept=auth.archive,
>
> > onupdate=db(db.mytable.id==record).update(field2='option2'),
> >                      deletable=False)
>
> I don't think SQLFORM takes an onupdate argument, and you would need to
> call SQLFORM.accepts, SQLFORM.validate, or SQLFORM.process after creating
> the SQLFORM in order to get validation/updating to happen. Perhaps you mean
> to use SQLFORM.grid() -- that does take an onupdate arg, but it must be a
> function (e.g., a lambda). But why are you automatically setting field2 to
> 'option2' on update -- don't you want to let the user choose the option? If
> not, make sure field2 isn't shown in the form.
>

I'll try these things, starting with sqlform.grid(), that maybe is
what I'm looking for...

> I recommend giving the relevant sections of ch. 7 a good
> read:http://web2py.com/book/default/chapter/07
>
> Anthony

Many thanks,
Rocco


[web2py] Re: SQLFORM: change field value after/in update

2011-11-26 Thread Anthony

On Saturday, November 26, 2011 11:40:27 AM UTC-5, Rocco De Marco wrote:
>
> db.mytable.field2.requires = IS_IN_SET(['option1'],['option2'])
>
I think you want:

IS_IN_SET(['option1', 'option2'])
 

> def update_mytable():
>
> record=request.args[0]
> form=SQLFORM(db.timbrata,
>  record,
>  onaccept=auth.archive,
>  
> onupdate=db(db.mytable.id==record).update(field2='option2'),
>  deletable=False)
>
I don't think SQLFORM takes an onupdate argument, and you would need to 
call SQLFORM.accepts, SQLFORM.validate, or SQLFORM.process after creating 
the SQLFORM in order to get validation/updating to happen. Perhaps you mean 
to use SQLFORM.grid() -- that does take an onupdate arg, but it must be a 
function (e.g., a lambda). But why are you automatically setting field2 to 
'option2' on update -- don't you want to let the user choose the option? If 
not, make sure field2 isn't shown in the form.

I recommend giving the relevant sections of ch. 7 a good 
read: http://web2py.com/book/default/chapter/07

Anthony