> > The first argument, 'dummy', of error( ) serves as the placeholder for
> > the instance that is normally passed as first argument to a method.
>
> You won't need the dummy argument since the instance is not passed by
> the error handling code, it is passed implicitly for bound methods.
>
> > If I define it as a method on one of the controllers I can't really
> > pass it to @error_handler decorating another method in another
> > controller, can I?
>
> Currently I see no reason why this should not be possible.
I've been investigating this issue a bit further and I'm still
confused. A minimal code demonstrating what I mean is this (note that
jsonifying tg_errors is no problem, I've added a jsonify rule for
that):
# I've tried two versions of my_error_handler, one with a dummy
# argument and one without it:
#
# def my_error_handler( dummy, tg_errors=None ):
# return dict( errors=str( tg_errors ), dummy=str( dummy ) )
def my_error_handler( tg_errors=None ):
return dict( errors=str( tg_errors ) )
class Root( tg.controllers.RootController ):
@expose( 'json' )
@error_handler( my_error_handler )
@validate( validators=dict( i=Int( ) ) )
def test( self, i=0 ):
return dict( i=i )
Now with the my_error_handler function having *no* dummy first
argument gives the following when accessing /test?i=hello
{"errors": "<myproject.controllers.Root object at 0x2045e10>", "tg_flash": null}
Strangely, the tg_errors argument is the Root object itself. Now if
my_error_handler *does* have the dummy first argument /test?i=hello
returns
{"dummy": "<myproject.controllers.Root object at 0x2047d90>",
"errors": "{'i': Invalid('Please enter an integer value',)}",
"tg_flash": null}
So the tg_errors argument has been passed correctly and the dummy
variable still contains the Root object. This made me believe I need
the dummy variable.
I don't understand fully what's going on especially because Chris
suggested that the dummy variable is not needed. Any ideas what is
really happening behind the scenes?
Cheers,
Daniel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---