In an application I'm working on I need to do some validation where
one of the form fields is validated as an int with a minimum value
based on the object model. I came up with a solution using nested
functions and classes, but I was wondering if there was another
preferred way to do this. If not maybe this would serve as a good
recipie. (BTW the "Int" validator here is actually a custom extension
of the formencode one which does not have support for min or max args
yet)
def obj_schema(obj):
class ObjSchema(Schema):
max_users = Int(min=obj.active_users)
return ObjSchema
def action(self):
obj = # retrieve obj
@validate(obj_schema(obj), form='action')
def doit(self):
if request.method == 'POST':
# update obj
model.ctx.current.flush()
redirect_to(action='index')
return render_response('form')
return doit(self)
-- Matt Good
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---