On Feb 28, 9:31 am, "Mark Ramm" <[EMAIL PROTECTED]> wrote:
> Oops I replied directly to Kevin on this.
>
> Also it's worth mentioning that Michael Bayer didn't particularly like
> this.
>
> I think my preferred solution would be to put this in a decorator, and pull
> it out of the expose decorator in a run_with_transaction() decorator or
> something like that...
>
> But that is a syntactic change, so I think the way to do it now is to keep
> the current behavior and break this in 2.0.
>
> What do you all think?
I think this is why I created Tools. ;) Put the START call in a new
Tool._setup, and the COMMIT call in either the on_end_resource or
on_end_request call as follows (this uses Dejavu, but should be easily
adaptable to TG):
def flush_sandbox():
if hasattr(cherrypy.request, "sandbox"):
try:
try:
cherrypy.request.sandbox.flush_all()
except:
cherrypy.log(format_exc(), "DEJAVU")
finally:
del cherrypy.request.sandbox
def try_flush_sandbox():
if cherrypy.response.stream:
# If the body is being streamed, we have to save the data
# *after* the response has been written out
cherrypy.request.hooks.attach('on_end_request', flush_sandbox)
else:
# If the body is not being streamed, we save the data now
if isinstance(cherrypy.response.body, types.GeneratorType):
cherrypy.response.collapse_body()
flush_sandbox()
class SandboxTool(cherrypy.Tool):
def _setup(self):
cherrypy.request.sandbox = endue.arena.new_sandbox()
cherrypy.Tool._setup(self)
tools.sandbox = SandboxTool('on_end_resource', try_flush_sandbox)
Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---