On 6/8/2010 11:16 AM, Diez B. Roggisch wrote:


Am 08.06.2010 um 17:54 schrieb Jim Steil:

I have the following in one of my TG 1.09 controllers.


   @tg.expose(content_type="application/pdf")
   @identity.require(identity.has_permission('purchasingReport'))
   def futurePriceAnalysisReport(self, *args, **kw):
       fromDate  = kw['fromDate']
       toDate = kw['toDate']
       plantId = kw['plant']
       excelPdf = kw['excelPdf']

       plant = Plant.get(plantId)
       fromDate = parse(fromDate)
       toDate = parse(toDate)
       userId = identity.current.user.id
       letters_file = StringIO.StringIO()
       fromDate = fromDate.strftime('%Y-%m-%d')
       toDate = toDate.strftime('%Y-%m-%d')
       fpa.futurePriceAnalysis(letters_file, plant.plantNumber,
                               fromDate, toDate, excelPdf)
       pdf = letters_file.getvalue()
       letters_file.close()

       return(pdf)


If the excelPdf variable is equal to 'xls' I want to change my content type to application/vnd.ms-excel. Is there a way for me to do so?


tg.response.headers["Content-Type"] = mytype should to the trick. Possibly you need to give

@tg.expose(content_type=CUSTOM_CONTENT_TYPE)

in the expose & then set it always. But at least in 2.04 you don't seem to need that.


Diez

That did it.  I did NOT have to change the @tg.expose.

Thanks much for the response.

    -Jim



Jim Steil
VP of Information Technology
Quality Liquid Feeds, Inc.
608.935.2345 office
608.341.9896 cell

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