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.u_implantee.unit_id==request.vars.unit_id),'u_implantee.zd_id',error_message=self.error_message)
(value)
        return e

and use with

....=IS_NOT_IN_DB_DDOWN_UIM(....,error_message=T("the error message")



On Jan 8, 11:25 am, tknack <tknac...@gmail.com> wrote:
> Thanks a lot Massimo, it works !
>
> Now,  I want to translate the error message in French and when I put
> it, like the others validators, here :
>
> db.u_implantee.zd_id.requires=IS_NOT_IN_DB_DDOWN_UIM
> (db,'zonedef.id','%
> (nom)s',error_message=('Cette valeur a deja ete saisie !'))
>
> the error stays in English.....
>
> forgiveness for my first steps
>
> On 8 jan, 18:08, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > You should not put the new validator in validators.py. Just put it in
> > the model that needs it.
>
> > Massimo
>
> > On Jan 8, 10:56 am, tknack <tknac...@gmail.com> wrote:
>
> > > Thanks Massimo, I made a mistake...
>
> > > But now, how can I solve that error :
>
> > >   File "applications/sefom/modules/validators.py", line 31, 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
>
> > > do I import db.py in validators.py ?
>
> > > T.
>
> > > On 8 jan, 16:02, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > should be
>
> > > > 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.u_implantee.unit_id==request.vars.unit_id),'u_implantee.zd_id')
> > > > (value)
> > > >         return e
>
> > > > Massimo
>
> > > > On Jan 8, 7:25 am, tknack <tknac...@gmail.com> wrote:
>
> > > > > Thanks Fran... now I think it's more clear in my head...
>
> > > > > again, I post my code with the right names...
>
> > > > > here's my applications.sefom.modules.validators.py (yes , my
> > > > > application name is 'sefom') :
>
> > > > > from gluon.validators import *
>
> > > > > class IS_NOT_IN_DB_DDOWN_UIM(object):
>
> > > > >     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_implantee.unit_id==request.vars.unit_id),'u_implantee.zd_id')
> > > > > (value)
> > > > >         return e
>
> > > > > here's the code I put in my model db.py:
>
> > > > > from applications.sefom.modules.validators import *
>
> > > > > db.define_table('zonedef',
> > > > >                 SQLField('nom'))
>
> > > > > db.zonedef.nom.requires=[IS_NOT_EMPTY(error_message='ne peut être
> > > > > vide!'),IS_NOT_IN_DB(db,'zonedef.nom')]
>
> > > > > db.define_table('u_nommee',
> > > > >                 SQLField('nom'),
> > > > >                 SQLField('description',length=128))
>
> > > > > # table des unités
> > > > > db.define_table('u_implantee',
> > > > >                 SQLField('unit_id',db.u_nommee),
> > > > >                 SQLField('zd_id',db.zonedef"),
> > > > >                 SQLField('nb_u','double'))
>
> > > > > db.u_implantee.zd_id.requires=IS_IN_DB(db,'zonedef.id','%(nom)s')
> > > > > db.u_implantee.unit_id.requires=IS_IN_DB(db,'u_nommee.id','%(nom)s : %
> > > > > (description)s')
>
> > > > > db.u_implantee.zd_id.requires=IS_NOT_IN_DB_DDOWN_UIM(db,'zonedef.id','%
> > > > > (nom)s')
>
> > > > > and here's the error I get :
>
> > > > >  File "applications/sefom/modules/validators.py", line 27, in __init__
> > > > >     IS_IN_DB.__init__(self,*a,**b)
> > > > > TypeError: unbound method __init__() must be called with IS_IN_DB
> > > > > instance as first argument (got IS_NOT_IN_DB_DDOWN_UIM instance
> > > > > instead)
>
> > > > > I'm using postgreSQL and I created a multi-column constraint on
> > > > > (zd_id,unit_id) for 'u_implantee' table. So the duet can't be present
> > > > > twice.
>
> > > > > Is there another solution ?
>
> > > > > Thanks a lot for your help.
>
> > > > > On 8 jan, 13:43, Fran <francisb...@googlemail.com> wrote:
>
> > > > > > On Jan 8, 9:03 am, tknack <tknac...@gmail.com> wrote:
>
> > > > > > > Is it correct to put my validator code in validator.py ?
>
> > > > > > I put my custom validators into a separate validators.py in my 
> > > > > > modules
> > > > > > folder & then import to the model like so:
> > > > > > from applications.myapplication.modules.validators import *
>
> > > > > > F
--~--~---------~--~----~------------~-------~--~----~
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