Commit d43cf354 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

Form: set response content type when called directly

Form.__call__ replaces page template call, so it is also responsible
to set the content type in response.

With Page Templates, ZopePageTemplate._exec (called by
Shared.DC.Scripts.Bindings.__call__ and _bindAndExec) sets the
response content type and calls pt_render. Form.__call__ also calls
pt_render, so to behave like page template, it should also sets the
response content type.

In erp5_xhtml_style, we don't notice this, because global_definitions
contains a setHeader call to set content type to html.
parent b407e915
...@@ -74,6 +74,11 @@ class TestERP5Form(ERP5TypeTestCase): ...@@ -74,6 +74,11 @@ class TestERP5Form(ERP5TypeTestCase):
self.assertTrue(self.form.formUnProxify()) self.assertTrue(self.form.formUnProxify())
self.assertTrue(self.form.formShowRelatedProxyFields()) self.assertTrue(self.form.formShowRelatedProxyFields())
def test_publish_set_content_type(self):
resp = self.publish(self.form.getPath())
self.assertIn(b"test string field", resp.getBody())
self.assertEqual(resp.getHeader('Content-Type'), 'text/html; charset=utf-8')
class TestProxify(ERP5TypeTestCase): class TestProxify(ERP5TypeTestCase):
......
...@@ -49,7 +49,7 @@ from AccessControl import Unauthorized, ClassSecurityInfo ...@@ -49,7 +49,7 @@ from AccessControl import Unauthorized, ClassSecurityInfo
from DateTime import DateTime from DateTime import DateTime
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from zExceptions import Redirect from zExceptions import Redirect
from Acquisition import aq_base from Acquisition import aq_base, aq_get
from Products.PageTemplates.Expressions import SecureModuleImporter from Products.PageTemplates.Expressions import SecureModuleImporter
from zExceptions import Forbidden from zExceptions import Forbidden
...@@ -676,7 +676,13 @@ class ERP5Form(Base, ZMIForm, ZopePageTemplate): ...@@ -676,7 +676,13 @@ class ERP5Form(Base, ZMIForm, ZopePageTemplate):
raise AccessControl_Unauthorized('This document is not authorized for view.') raise AccessControl_Unauthorized('This document is not authorized for view.')
else: else:
container = None container = None
pt = getattr(self,self.pt) pt = getattr(self, self.pt)
request = aq_get(self, 'REQUEST', None)
if request is not None:
response = request.response
if 'content-type' not in response.headers:
response.setHeader('content-type', self.content_type)
extra_context = dict( container=container, extra_context = dict( container=container,
template=self, template=self,
form=self, form=self,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment