[Zope3-checkins]
SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/
make sure ViewPageTemplateFile sets the Content-Type header if not
Fred L. Drake, Jr.
fdrake at gmail.com
Wed Sep 29 13:42:44 EDT 2004
Log message for revision 27707:
make sure ViewPageTemplateFile sets the Content-Type header if not
already set
(merged from Zope 3 trunk revision 27706)
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/tests/test_viewzpt.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/viewpagetemplatefile.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/tests/test_viewzpt.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/tests/test_viewzpt.py 2004-09-29 17:39:16 UTC (rev 27706)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/tests/test_viewzpt.py 2004-09-29 17:42:44 UTC (rev 27707)
@@ -85,6 +85,24 @@
self.failUnless(the_view is views[the_view_name])
+ def test_render_sets_content_type_unless_set(self):
+ from zope.publisher.browser import TestRequest
+ t = ViewPageTemplateFile('test.pt')
+
+ self.request = TestRequest()
+ response = self.request.response
+ self.assert_(not response.getHeader('Content-Type'))
+ t(self)
+ self.assertEquals(response.getHeader('Content-Type'), 'text/html')
+
+ self.request = TestRequest()
+ response = self.request.response
+ response.setHeader('Content-Type', 'application/x-test-junk')
+ t(self)
+ self.assertEquals(response.getHeader('Content-Type'),
+ 'application/x-test-junk')
+
+
class TestViewZPTContentType(unittest.TestCase):
def testInitWithoutType(self):
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/viewpagetemplatefile.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/viewpagetemplatefile.py 2004-09-29 17:39:16 UTC (rev 27706)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/pagetemplate/viewpagetemplatefile.py 2004-09-29 17:42:44 UTC (rev 27707)
@@ -42,7 +42,11 @@
namespace = self.pt_getContext(
request=instance.request,
instance=instance, args=args, options=keywords)
- return self.pt_render(namespace)
+ s = self.pt_render(namespace)
+ response = instance.request.response
+ if not response.getHeader("Content-Type"):
+ response.setHeader("Content-Type", self.content_type)
+ return s
def __get__(self, instance, type):
return BoundPageTemplate(self, instance)
More information about the Zope3-Checkins
mailing list