From 1bd31125cc417953c45a783d725abd0b23f77d05 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Mon, 17 Aug 2009 08:53:12 +0000
Subject: [PATCH] set a content-disposition header with an appropriate filename
 and cache headers in PDFDocument.index_html() if no format is specified.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28405 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/PDFDocument.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/PDFDocument.py b/product/ERP5/Document/PDFDocument.py
index 685c35e438..7e50612bf8 100644
--- a/product/ERP5/Document/PDFDocument.py
+++ b/product/ERP5/Document/PDFDocument.py
@@ -28,7 +28,8 @@
 import tempfile, os, cStringIO
 
 from AccessControl import ClassSecurityInfo
-from Products.CMFCore.utils import getToolByName
+from Products.CMFCore.utils import getToolByName, _setCacheHeaders,\
+    _ViewEmulator
 
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, interfaces
 from Products.ERP5Type.Cache import CachingMethod
@@ -79,7 +80,14 @@ class PDFDocument(Image, ConversionCacheMixin):
       it is always a zip because multi-page pdfs are converted into a zip
       file of many images
     """
-    if format is None:
+    _setCacheHeaders(_ViewEmulator().__of__(self), {'format' : format})
+    if format is '':
+      if self.getSourceReference() is not None:
+        filename = self.getSourceReference()
+      else:
+        filename = self.getId()
+      RESPONSE.setHeader('Content-Disposition',
+                         'attachment; filename="%s"' % filename)
       RESPONSE.setHeader('Content-Type', 'application/pdf')
       return str(self.data)
     if format in ('html', 'txt', 'text'):
-- 
2.30.9