I am using an IS_NOT_IN_DB validator with SQLFORM. The SQLFORM is also an
interface to update and create (by setting the fields default values). When
the form runs through form.accepts, since it is a factory IS_NOT_IN_DB fails
on validation, since set_self_id is actually a dictionary (from
SQLFORM.factory). The only way around this is to remove the IS_NOT_IN_DB
validator from the field, and validate this after form.accepts().

db.table.field.name.default = row.name
db.table.field.email.default = row.email <- unique

db.table.field.email.requires = None

SQLFORM.factory(db.table.field.name, db.table.field.email)

if form.accepts(request.vars, session):
    validate_email = IS_NOT_IN_DB(db, 'field.email')
    validate_email.set_self_id(row.id)
    (value, error) = validate_email(form.vars.email)

-Thadeus




On Sun, Nov 29, 2009 at 8:52 AM, mdipierro <mdipie...@cs.depaul.edu> wrote:

> Please state your problem again and check with latest trunk first.
>
> On Nov 29, 1:53 am, Thadeus Burgess <thade...@thadeusb.com> wrote:
> > Actually, the problem is I am using an IS_NOT_IN_DB with an
> SQLFORM.factory.
> > Then I use update_record.
> >
> > -Thadeus
> >
> > On Sun, Nov 29, 2009 at 1:37 AM, Thadeus Burgess <thade...@thadeusb.com
> >wrote:
> >
> > > I am attempting to use
> >
> > > row.update_record(....)
> >
> > > -Thadeus
> >
> > > On Sun, Nov 29, 2009 at 1:30 AM, Thadeus Burgess <
> thade...@thadeusb.com>wrote:
> >
> > >> I am actually having this problem with IS_NOT_IN_DB for updating
> > >> records...
> >
> > >> Just attempting to use my basic slug example in my other post.
> >
> > >> -Thadeus
> >
> > >> On Fri, Nov 27, 2009 at 10:34 AM, mdipierro <mdipie...@cs.depaul.edu
> >wrote:
> >
> > >>> If a validator has a method set_self_id, it is called automatically
> by
> > >>> web2py upon edit.
> >
> > >>> On Nov 27, 10:22 am, __Kyo__ <iacastil...@gmail.com> wrote:
> > >>> > Hi thanks a lot for the help, i put this code in my model, and it
> runs
> > >>> > fine.
> >
> > >>> > inventory=db().select(db.Inventory.ALL)
> > >>> > for i in inventory:
> > >>> >     if db((i.idProducto==db.Inventory.idProduct)&
> > >>> > (i.idCountry==db.Inventory.idCountry)).count()>1:
> > >>> >         db(db.Inventory.id == i.id).delete()
> >
> > >>> > However I'd like to learn how modify the class becouse i think is
> the
> > >>> > best way to do it. I can't understand the code a lot. So please,
> > >>> > how do i edit this code for settings the id of the current record
> you
> > >>> > can prevent the check on update?
> >
> > >>> >     def set_self_id(self, id):
> > >>> >         self.record_id = id
> >
> > >>> > On 27 nov, 01:41, mdipierro <mdipie...@cs.depaul.edu> wrote:
> >
> > >>> > > Look into gluon.validators.IS_NOT_IN_DB
> >
> > >>> > > specifically:
> >
> > >>> > >     def set_self_id(self, id):
> > >>> > >         self.record_id = id
> >
> > >>> > > By settings the id of the current record you can prevent the
> check on
> > >>> > > update.
> >
> > >>> > > Massimo
> >
> > >>> > > On Nov 26, 4:32 pm, __Kyo__ <iacastil...@gmail.com> wrote:
> >
> > >>> > > > Hi, i use this code in my application, it works very good when
> i
> > >>> > > > insert a new record, but i have a little problem when i want to
> > >>> update
> > >>> > > > a registry. For example:
> >
> > >>> > > > I have un my table inventory: product, country, quantity
> >
> > >>> > > > If i insert pencil, canada, 40 it inserts fine
> >
> > >>> > > > then if i want to insert again pencil, canada, 50 it doesnt
> insert
> > >>> > > > beacuse i already have pencils in canada. This is working fine.
> >
> > >>> > > > My problem is here, in the update. For example
> >
> > >>> > > > I want to update my number of pencils in Canada, beacause i buy
> > >>> > > > another 50 pencils. I put update
> > >>> > > > pencil, canada, 90
> >
> > >>> > > > But it says it already have pencils in canada, its like i am
> > >>> inserting
> > >>> > > > a new registry and not doing an update. How can i solve this?
> >
> > >>> > > > This is my validator, is in the model:
> >
> > >>> > > > class IS_NOT_IN_DB_DDOWN_UIM(IS_IN_DB):
> > >>> > > >     def __init__(self,*a,**b):
> > >>> > > >         IS_IN_DB.__init__(self,*a,**b)
> > >>> > > >     def __call__(self,value):
> > >>> > > >         e=IS_IN_DB.__call__(self,value)
> > >>> > > >         if e[1]:return e             e=IS_NOT_IN_DB(db
> >
> > >>>
> (db.Inventory.idProduct==request.vars.idProduct),'Inventory.idCountry',erro­r_message=self.error_message)
> > >>> > > > (value)
> > >>> > > >         return e
> >
> > >>> > > > db.Inventory.idCountry.requires=IS_NOT_IN_DB_DDOWN_UIM
> > >>> > > > (db,'Country.id','%(nCountry)s',error_message="The product is
> > >>> already
> > >>> > > > in this country.")- Ocultar texto de la cita -
> >
> > >>> > > - Mostrar texto de la cita -
> >
> > >>> --
> >
> > >>> You received this message because you are subscribed to the Google
> Groups
> > >>> "web2py-users" group.
> > >>> To post to this group, send email to web...@googlegroups.com.
> > >>> To unsubscribe from this group, send email to
> > >>> web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> <web2py%2bunsubscr...@googlegroups.com<web2py%252bunsubscr...@googlegroups.com>
> >
> > >>> .
> > >>> For more options, visit this group at
> > >>>http://groups.google.com/group/web2py?hl=en.
> >
> >
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to
> web2py+unsubscr...@googlegroups.com<web2py%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/web2py?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to