you can use 
Decoration.get_decoration(controller_method).register_hook('after_render',
callable)
and callable will be execute after rendering the template with the
rendering result as parameter.

On Mon, Sep 19, 2011 at 3:32 PM, León Domingo <[email protected]> wrote:
> Hi Alessandro,
> And how would it be this way? I don't know exactly how "after_render"
> has to be used. As far as I know, you define a function with a
> "response" parameter and then a decorator "after_render" passing that
> function in.
>
> def _after_render(r):
>  # something to be done
>  r.content_type = 'application/pdf'
>  r.body = to_pdf(r.body)
>
> @expose('foo.html')
> @after_render(_after_render)
> def foo(self, *args, **kwargs):
>   return dict(....)
>
> is it correct? I was trying this way but...can I modify "response"
> inside "_after_render"? I thought it was not possible...
>
> Thanks
>
> León
>
> On 19 sep, 15:13, Alessandro Molina <[email protected]>
> wrote:
>> Uhm, I would suggest you to setup a after_render hook and decide if
>> the render result must be converted to a PDF or not.
>> In the case it doesn't have to be converted you can leave it go as
>> HTML, otherwise you can call wkhtmltopdf
>>
>>
>>
>>
>>
>>
>>
>> On Sun, Sep 18, 2011 at 9:54 AM, León Domingo <[email protected]> wrote:
>> > Hi,
>> > I've created a little function that makes use of wkhtmltopdf (http://
>> > code.google.com/p/wkhtmltopdf/) to get PDF content from HTML content.
>>
>> > I would like to use some controllers to get a PDF version of the HTML
>> > content defined in the corresponding template.
>>
>> >   @expose('foo.html')
>> >   def foo(self, *args, **kwargs):
>> >       return dict(....)
>>
>> > I've been making some experiments with a middleware class.
>>
>> >   response.content_type = 'application/pdf'
>> >   response.body = to_pdf(response.body)
>>
>> >   return response(environ, start_response)
>>
>> > It works but I need something to know if I have to make the
>> > translation or not
>>
>> >   if is_a_suitable_response:
>> >       response.content_type = 'application/pdf'
>> >       response.body = to_pdf(response.body)
>>
>> >   return response(environ, start_response)
>>
>> > and I don't know how I can "mark" the response to do so. In the other
>> > hand, I don't know if this is the right way to do that.
>>
>> > Thanks a lot
>>
>> > León
>>
>> > --
>> > 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 
>> > athttp://groups.google.com/group/turbogears?hl=en.
>
> --
> 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.
>
>

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