You can set either a field validation:
Validation function:
database_username_re = re.compile('^[a-z0-9_]{2,16}$', re.IGNORECASE)
def validate_database_param(param):
if database_username_re.match(param):
return True
else:
return unicode('Value must be between 2 and 16 characters and
can only contain uppercase and lowercase alphanumeric characters or an
underscore')
Schema definition:
databasename = colander.SchemaNode(
colander.String(),
validator=colander.Function(validate_database_param),
title = 'Database Name',
)
Or, in your actual Schema call:
def validate_userpass_existing(form, value):
"""
checking to make sure we have a user/pass OR an existing user
"""
exc = None
if value['databasename']:
db = DBSession.query(cp_database). \
filter(cp_database.device_id==value['device_id']). \
filter(cp_database.databasename==value['databasename']).first()
if db:
exc = colander.Invalid(form, 'Database name already in
use.')
exc['databasename'] = 'Cannot create a duplicate database'
if exc:
raise exc
schema = DBAddSchema(validator=validate_userpass_existing). \
bind(user_list=grants, device_list=devices, \
csrf_token=request.session.get_csrf_token())
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.