Fran, the following validator seems to work as per your needs:

class THIS_NOT_IN_DB(object):
    def __init__(self,dbset,field,this,error_message='value already in
database!'):
        if hasattr(dbset,'define_table'): self.dbset=dbset()
        else: self.dbset=dbset
        self.field=field
        self.value=this
        self.error_message=error_message
        self.record_id=0
    def set_self_id(self,id): self.record_id=id
    def __call__(self,value):
        tablename,fieldname=str(self.field).split('.')
        field=self.dbset._db[tablename][fieldname]
        rows=self.dbset(field==self.value).select(limitby=(0,1))
        if len(rows)>0 and str(rows[0].id)!=str(self.record_id):
            return (self.value,self.error_message)
        return (value,None)

example:
db.define_table('gis',
  SQLField('key'),
  SQLField('service')
)
db.gis.key.requires=THIS_NOT_IN_DB(db
(db.gis.service==request.vars.service),'gis.service',request.vars.service,'service
already in use')
db.gis.service.requires=IS_IN_SET(['google','multimap','yahoo'])

so the validation of one field (key) depends on the value of another
(service).

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to