On 6/6/07, Max Ischenko <[EMAIL PROTECTED]> wrote:
> Hello,
>
>  I am not very happy with the default validation scheme suggested by Pylons
> and trying to design my own.
>
>  The idea is to let the code handle main code path (data is valid) and
> handle validation error separatedly. I want to be able to set
> validation_handler which is then invoked by BaseController when validation
> fails.
>
>  E.g.
>
>  class SomeController(BaseController)
>      def index(self):
>          code = get_request_param('code', validator=...)
>          # do something with validated parameter "code"
>      index.validation_handler = lambda errors: Response('Oops!')
>
>  class BaseController(WSGIController):
>      def __call__(self, environ, start_response):
>          # ...
>          try:
>              return WSGIController.__call__(self, environ, start_response)
>          except ValidationError, e:
>              validation_handler = getattr(XXX, 'validation_handler', None)
> or default_validation_handler
>              return validation_handler(e)
>
>  I struggle to find the XXX object I can query to access the
> validation_handler (such as the one defined for index()).
>
>  Any ideas?

Somewhere in the environ, there's the Routes stuff.  You can use that
to figure out which action was executed.  I usually just print out the
environ and start poking around.  Once you know what action was
executed, get the actual method via "getattr(self, action_name)".
>From there, you can do "getattr(action_method, 'validation_handler',
None)".  Make sense?

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to