On Dec 13, 2006, at 12:07 AM, Dennis Muhlestein wrote:

>
> OK, I Have a working solution but I don' t think it's very pretty.  It
> appears Alberto was right about the rules being optimized if they  
> could
> be determined statically.  I didn't detect that earlier though because
> the func_original function wasn't returning the correct function.
> Anyhow.. here is how this works.

Actually func_original was doing what it should... The problem was  
that the "func" passed to rwt is not the function that we thought it  
was but a gf created on the fly by "expose" to support multiple  
output formats by expose (take a look at turbogears.tests.test_expose  
if interesed).

>
> 1) Patch TG to user MultiorderGenericFunction
>  I got an ambiguous function def error when I tried it with stock TG.
> .....
>
> 2) Create a no_transaction decorator
> from turbogears.decorator import weak_signature_decorator
>
> ....
>
> 4) create the no trans method.  Order=-1 is important so you go before
> the default sa_rwt, and so_rwt conditions.
> @run_with_transaction.when("is_no_trans()",order=-1)
> def _no_trans_for_this_method(func, *args, **kw):
>       log.debug ( "No Trans Method" )
>       return func(*args, **kw)
>
>
> 5) In your controller code you can now decorate like this:
> @no_transaction()
> @expose()
> def something(self): pass
>
> Note that order is indeed important for no_transaction because the
> request attribute must be set before it is tested for in the expose
> method.
>
>
> Well, this has been a long thread.  This solution works for me but I'm
> not sure it's very suited to suggest to others in the same boat.
> Anyone have a better solution?
>

Phew! We should do something, really,  in TG 2.0 regarding  
decorators... this is really going through rims of fire, snow, ice  
and splinters under one's toe nails for something that should have  
been *much* easier... :D Glad you finally got something that works :)  
I can't really thing of a better solution given the current state of  
affairs... ;)

Alberto

P.S Should I comitt the patch? If so please file a ticket with it at  
the Trac so we don't forget it at the CHANGELOG for 1.0b3
P.P.S. Something I've learnt from this thread and write in a big  
sticker in front of my desk: don't ever, ever again think about  
abusing decorators :)

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

Reply via email to