Hello,

I am trying to call it like so...

db.domains.name.requires =[IS_VALID_A(db, db.domains.name), IS_NOT_IN_DB(db, 
db.domains.name)]

This is the first time I've tried to write a class so it's all new to me. I 
"copied" an example.


----- Original Message -----
From: "Anthony" <abasta...@gmail.com>
To: web2py@googlegroups.com
Cc: "Jimmystewpot" <mail...@oranged.to>
Sent: Monday, 18 June, 2012 12:59:16 AM
Subject: Re: Custom validators error messages



class IS_VALID_A(object): 
Name = 'IS_VALID_A' 
def __init__(self, object, error_message='Invalid Domain Name'): 



Why is "object" the second argument of __init__? What is "object", and are you 
doing anything with it? Are you passing in a value for "object" when you 
instantiate the validator? 


self.error_message = error_message 
self.d = object 
self.DEBUG = 'YES' 

def __call__(self, value): 
if self.checkrecord(value) == 'valid': 
return (value, None) 
else: 
return (value, (self.error_message)) 

def checkrecord(self, data): 
value = 'invalid' 
return value 


In theory that should always error and give me a message saying 'Invalid Domain 
Name'. 



Yes, it should, and in fact it does as long as you pass a value for "object" 
when you instantiate. Can you show the code where you use the validator (i.e., 
where it is instantiated and then later called)? 


Anthony 

-- 



Reply via email to