Personal tools
You are here: Home Weblog Archive 2006 August 27 Creating an Archetypes validator
Document Actions
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Creating an Archetypes validator

by tibi last modified 2006-08-27 18:12
Filed Under:

Archetypes validators are used in the schema definition for a field. Default validators include isEmail, isURL, etc.

This is how to create a new validator:

First, the validator has to be registered with Archetypes, or zope will complain at startup and ignore the validator. So add something like this in the __init__.py of the product:

from Products.validation import validation
from validators import SamePasswordValidator
validation.register(SamePasswordValidator('isSamePassword'))
Next, the source code for the validator (validators.py):
from Products.validation.interfaces import ivalidator

class SamePasswordValidator:
__implements__ = (ivalidator,)

def __init__(self, name):
self.name = name

def __call__(self, value, *args, **kwargs):
instance = kwargs.get('instance', None)
req = kwargs['REQUEST']
pass1 = req.form.get('password', None)
if pass1 <> value:
return """Validation failed: You need to enter the password twice."""
Weblog
Atom
RDF
RSS 2.0
Powered by Quills
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: