Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
validation.validators.ExpressionValidator.ExpressionValidator Class Reference
Collaboration diagram for validation.validators.ExpressionValidator.ExpressionValidator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __call__

Public Attributes

 expression
 errormsg
 compiledExpression

Static Public Attributes

string name = 'talesexpressionvalidator'

Static Private Attributes

tuple __implements__ = (IValidator,)

Detailed Description

Validator for TALES Expressions

Basically, if the expression compiles it's a valid expression,
otherwise it's invalid and you get a message saying that the
expression has errors.


>>> val=ExpressionValidator('python: int(value) == 5')
>>> class C:i=1
>>> c=C()
>>> val(5,c) is True
True

now lets fail a test
>>> val(4,c) 
'validation failed, expr was:python: int(value) == 5'

It is also possible to specify the error string

>>> val=ExpressionValidator('python: int(value) == 5', 'value doesnt match %(value)s')
>>> val(4,c) 
'value doesnt match 4'

Definition at line 28 of file ExpressionValidator.py.


Constructor & Destructor Documentation

def validation.validators.ExpressionValidator.ExpressionValidator.__init__ (   self,
  expression = None,
  errormsg = None 
)

Definition at line 59 of file ExpressionValidator.py.

00059 
00060     def __init__(self,expression=None,errormsg=None):
00061         self.expression=expression
00062         self.errormsg=errormsg
00063         if expression:
00064             self.compiledExpression=getEngine().compile(expression)


Member Function Documentation

def validation.validators.ExpressionValidator.ExpressionValidator.__call__ (   self,
  value,
  instance,
  args,
  kwargs 
)

Definition at line 65 of file ExpressionValidator.py.

00065 
00066     def __call__(self, value, instance, *args, **kwargs):
00067         kw={
00068            'here':instance,
00069            'object':instance,
00070            'instance':instance,
00071            'value':value,
00072            'args':args,
00073            'kwargs':kwargs,
00074            }
00075            
00076         context=getEngine().getContext(kw)
00077         res=self.compiledExpression(context)
00078         
00079         if res:
00080             return True
00081         else:
00082             if self.errormsg:
00083                 return self.errormsg % kw
00084             else:
00085                 return 'validation failed, expr was:'+self.expression
00086            
00087 
00088 #validation.register(TALESExpressionValidator())

Here is the call graph for this function:


Member Data Documentation

Definition at line 55 of file ExpressionValidator.py.

Definition at line 63 of file ExpressionValidator.py.

Definition at line 61 of file ExpressionValidator.py.

Definition at line 60 of file ExpressionValidator.py.

string validation.validators.ExpressionValidator.ExpressionValidator.name = 'talesexpressionvalidator' [static]

Definition at line 57 of file ExpressionValidator.py.


The documentation for this class was generated from the following file: