I was wondering why this code has been removed. I find it very
usefull.
#TODO: Consider depricating this in favor of pylons validate decorator
class validate(object):
"""Validate regesters validator on the decorated function.
:Parameters:
validator
Valdators
error_handler
Assign error handler
"""
def __init__(self, validator=None, error_handler=None, **kw):
if not hasattr(validator, 'to_python') and hasattr(validator,
'validator'):
validator = validator.validator
elif kw:
assert validator is None, \
'validator must not be specified with additional
keyword arguments'
validator = kw
if not isinstance(validator, formencode.Schema):
validator = _schema(validator)
self.validator = validator
self.error_handler = error_handler
def __call__(self, func):
deco = TGDecoration.get_decoration(func)
deco.validator = self.validator
deco.error_handler = self.error_handler
return func
The way I use this code is to retrieve the target form from my widget
cache in the following manner:
class DBMechanicValidator(object):
@property
def validator(self):
if not pylons.request.method == 'POST':
return func(self, *args, **kwargs)
if post_only:
params = pylons.request.POST.copy()
else:
params = pylons.request.params.copy()
sprocket = self.sprockets[params['dbsprockets_id']]
form = sprocket.view.widget
return form
Now, maybe I could write a formencode.Schema that does the same thing,
but i think I need to be pointed in the right direction to get that
working.
cheers.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---