Massimo,

here's what I wrote in gluon/validator.py :

class IS_NOT_IN_DB_WITH_DROP(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.u.unit_id==request.vars.unit_id),'u.zd_id')(value)
        return e

and in my db.py:

db.u.zd_id.requires=IS_NOT_IN_DB_WITH_DROP(db,'zonedef.id','%(nom)s')

and I've got an error :

  File "gluon/validators.py", line 723, in __call__
    e=IS_NOT_IN_DB(db
(db.u_implantee.unit_id==request.vars.unit_id),'u_implantee.zd_id')
(value)
NameError: global name 'db' is not defined

It seems it's normal, because code in validator.py may be generic one.

So,

Is it correct to put my validator code in validator.py ?

Maybe you wanted I put it somewhere else ?

Please, forgive my lack of experience

T



On 6 jan, 19:00, mdipierro <mdipie...@cs.depaul.edu> wrote:
> for now use this. This is a case I never should about before.
>
> class MY_ODD_VALIDATOR(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.u.unit_id==request.vars.unit_id),'u.zd_id')(value)
>            return e
>
> db.u.zd_id.requires=MY_ODD_VALIDATOR(db,'zonedef.id','%(nom)s')
>
> On Jan 6, 11:40 am, tknack <tknac...@gmail.com> wrote:
>
> > Hi Massimo,
>
> > Yes, it works ! But when I try to use IS_NOT_IN_DB with IS_IN_DB, I
> > can't obtain a drop down list, even if I change the order of the
> > lines. Here's my code :
>
> > db.define_table('zonedef',
> >                 SQLField('nom'))
>
> > db.zonedef.nom.requires=[IS_NOT_EMPTY(error_message='can't be
> > empty!'),IS_NOT_IN_DB(db,'zonedef.nom')]
>
> > db.zonedef.represent=lambda zonedef:
> > A(zonedef.nom,_href=t2.action('update',zonedef.id))
>
> > db.define_table('u_name',
> >                 SQLField('nom'),
> >                 SQLField('description',length=128))
>
> > db.define_table('u',
> >                 SQLField('unit_id',db.u_name),
> >                 SQLField('zd_id',db.zonedef),
> >                 SQLField('nb_u','double'))
>
> > db.u.zd_id.requires=IS_IN_DB(db,'zonedef.id','%(nom)s')
> > db.u.unit_id.requires=IS_IN_DB(db,'u_name.id','%(nom)s : (description)
> > s')
>
> > db.u.zd_id.requires=IS_NOT_IN_DB(db
> > (db.u.unit_id==request.vars.unit_id),'u.zd_id')
>
> > Can you help me to fix it, Massimo ?
>
> > On 12 déc 2008, 23:24, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > No. validators are associated to one field in the sense that only one
> > > field will report the error.
>
> > > db.define_table('t',SQLField('f1'),SQLField('f'2'))
> > > db.t.f2.requires=IS_NOT_IN_DB(db(db.t.f1==request.vars.f1),'t.f2')
> > >  OR
> > > db.t.f1.requires=IS_NOT_IN_DB(db(db.t.f2==request.vars.f2),'t.f1')
>
> > > are equivalent and do exactly what you ask.  except that the former
> > > associates the error with the f1 value and the second to the f2 value.
> > > They both generate the query
>
> > > db((db.t.f1==request.vars.f1)&(db.t.f2==request.vars.f2)).count()
>
> > > Massimo
>
> > > On Dec 12, 4:01 pm, DenesL <denes1...@yahoo.ca> wrote:
>
> > > > On Dec 12, 4:07 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > I still do not see why you cannot use IS_NOT_IN_DB(sqlset,....) You
> > > > > must have access to the variables that you want tovalidate.
>
> > > > Correct me if I am wrong but IS_NOT_IN_DB only looks at the value of
> > > > one field.
> > > > From validators.py:
> > > > rows=self.dbset(field=value).select(limitby=(0,1))
>
> > > > What we are thinking is:
> > > > [field1value,field2value,field3value,...] as a row is not in the DB.
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@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