Ok, I am really close to having a solution that should make everyone
happy.  It involves the following change in pylons:

diff -r 28eed5438061 pylons/decorators/expose.py
--- a/pylons/decorators/expose.py       Sun Jan 13 17:29:05 2008 -0800
+++ b/pylons/decorators/expose.py       Thu Jan 24 21:46:28 2008 -0700
@@ -203,6 +203,9 @@ class validate(object):
         self.validators = validators
         self.error_handler = error_handler

+    def _before_validate(self, controller, params):
+        pass
+
     def __call__(self, func):
         deco = Decoration.get_decoration(func)
         deco.validation = self

and the following change to Turbogears:
Index: tg/decorated.py
===================================================================
--- tg/decorated.py     (revision 4039)
+++ tg/decorated.py     (working copy)
@@ -21,9 +21,12 @@
 class DecoratedController(WSGIController):

     def _perform_validate(self, controller, params):
+        print 'decorated performvalidate', controller, params
         validation = getattr(controller.decoration, 'validation',
None)
+        print '&'*80, validation
         if validation is None:
             return params
+        validation._before_validate(controller, params)

         new_params=params
         if isinstance(validation.validators, dict):
@@ -103,7 +106,7 @@
                                       namespace=namespace)
         return result

-    def _handle_validation_errors(self, controller, exception):
+    def _handle_validation_errors(self, controller, exception, args):
         pylons.c.form_errors = exception.error_dict
         pylons.c.form_values = exception.value

@@ -111,7 +114,8 @@
         if error_handler is None:
             error_handler = controller

-        output = error_handler(controller.im_self)
+        print args
+        output = error_handler(controller.im_self, args)

         return error_handler, output

@@ -140,7 +144,7 @@

         except formencode.api.Invalid, inv:
             controller, output =
self._handle_validation_errors(controller,
-                                                                inv)
+                                                                inv,
args)

         # Render template
         controller.decoration.run_hooks('before_render', remainder,
params,


What this does is allow a hook for the validator to do whatever you
want.  You just extend validate and implement _before_validate() and
set self.validators to what you actually want for a validator.  It's
convenient for me to use the params to find the form....

Anyway it *almost* works, the only problem I am seeing is that when
the error_handler is called, the args from the previous calls are not
getting passed through.  If anyone has an idea on how this might be
done I think this would be a really nice implementation.

cheers.
-chris

On Jan 24, 6:26 pm, "Mark Ramm" <[EMAIL PROTECTED]> wrote:
> > > Alberto particularly wanted to be able to supply his own validate
> > > in ToscaWidgets, and if there's signficant benefit in letting
> > > people tweek validate, it makes sense to decouple it from the
> > > controller so that people could much more reasonably do that.
>
> > I can certainly understand that, but again, I think we can
> > accomplish this without having to sacrifice the elegance of the
> > current solution, or making the decorator more complex than it needs
> > to be.  I'd rather see us design @validate to be extensible by
> > passing in callables.
>
> Well, I think the stack trace is a bit confused by all the
> inspect_cal, perform_call, stuff in the controller anyway, but I
> pretty much agree that if both validate and expose maintain the same
> form there is a nice symmetry to that.   Plus I agree that the current
> validation setup is easy to understand, and I hope adding a callable
> and the specific hook toscawidget hook where you can pass a form (or
> anything with a .validate method) to the @validate, and possibly the
> suggested ability to pass a generic callable in, should provide enough
> flexibility.
>
> But I think we should wait for Alberto to make his argument before we
> make a final decision.   But in the meantime I'm adding tickets for
> improving the current validation system.
>
> --Mark Ramm
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to