I found two use cases where it would be nice to postprocess the
Response object in the base controller:
1) To do the Tidy validation in my previous email.
2) To apply a site template independent of the controller templates.
(Useful if the regular templates use multiple engines, so that you
don't have to maintain the same site template for every engine.)
However, the base controller just does this:
return WSGIController.__call__(self, environ, start_response)
This means the Response comes and goes before you can see it.
I got it to work by overriding the superclass method:
===
# start_response and routes_dict bla bla bla
# I don't use .__before__ or .__after__
response = self._dispatch_call()
# My code here
if isinstance(response, basestring):
c.content = response
response = render("genshi", "site_genshi")
else:
c.content = response.content
response.content = render("genshi", "site_genshi")
# End my code
if hasattr(response, 'wsgi_response'):
# Copy the response object into the testing vars if we're testing
if 'paste.testing_variables' in environ:
environ['paste.testing_variables']['response'] = response
return response(environ, start_response)
elif isinstance(response, basestring):
resp = pylons.Response(response)
return resp(environ, start_response)
return response
===
This works but it's a little annoying that I have to check for both
string and Response, because the other place it's tested is inside an
'elif'.
Also I don't understand, why do the two special cases call the
response before returning it, while the last case just returns the
response.
I'd suggest cleaning this up so there's a point where there's a
Response object exists in all cases, and then calling:
self.__postprocess_response(self, resp)
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---