kgk schrieb:
> Setting content type has become difficult.  I am still not sure how to
> use
> 1. @expose (content_type = CUSTOM_CONTENT_TYPE)
>      pylons.response.headers['Content-Type'] = 'text/xml'
> vs
> 2. @expose (content_type = "text/xml", custom_format = "xml")
>     use_custom_format ('xml')
> vs
> 3.  @expose (content_type = "text/xml")


   from tg.controllers import CUSTOM_CONTENT_TYPE
   from tg import (
     expose,
     flash,
     request,
     response,
   )


   @expose(content_type=CUSTOM_CONTENT_TYPE)
   @require(not_anonymous())
   @validate(license_select_form, error_handler=index)
   @validate(hardware_code_form, error_handler=enter_hardware_code)
   def download_authorization_file(self, license_id, hardware_code):

       rh = response.headers
       rh['Content-Type'] = 'application/octet-stream; charset=utf-8'
       disposition = 'attachment; filename="Authorize_%s.auz"' % str( 
                                                              hardware_code)
       rh['Content-disposition'] = disposition
       rh['Pragma'] = 'public' # for IE
       rh['Cache-control'] = 'max-age=0' #for IE
       return authorizations


Works without a hitch for us (TG 2.0.1)

> 
> 
> 
> I could never  1 or 2 or 3 to work properly in tg2.0.X .. If somebody
> has a good example or explanation I
> would appreciate seeing it .
> 
> 
> 3 does work in tg2.1 but  does not work with nested functions i.e.
> 
> class RootController (BaseController):
>      @expose ()
>      def  test_l1 (self, *path, *kw):
>           return self.testl2 (self)
> 
>      @expose (content_type="text/xml")
>      def  test_l2 (self, *path, *kw):
>           return "<xml/>"
> 
> 
> A request to test_l1 will return with content_type "text/html"
> Is there any way around this?

No. exposition is dealt with in TG2 itself before delegating execution 
to the action - nesting actions won't work because of this.

Diez

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