Commit 731bdd24 authored by Tres Seaver's avatar Tres Seaver

LP #496941: Remove all mention of ``standard_html_header`` and

``standard_html_footer`` from default DTML content.
parent 8bc9075e
......@@ -40,6 +40,9 @@ Features Added
Bugs Fixed
++++++++++
- LP #496941: Remove all mention of ``standard_html_header`` and
``standard_html_footer`` from default DTML content.
- Fixed a regression in Products.PageTemplates that meant filesystem templates
using Products.Five.browser.pagetemplatefile would treat TALES path
expressions (but not python expressions) as protected code and so attempt
......
......@@ -175,10 +175,14 @@ class DTMLDocumentTopic(HelpTopicBase, DTMLDocument):
default_topic_content="""\
<dtml-var standard_html_header>
<html>
<head><title><dtml-var title_or_id></title>
</head>
<body bgcolor="#FFFFFF">
<h2><dtml-var title></h2>
<p>This is the <dtml-var id> Help Topic.</p>
<dtml-var standard_html_footer>
</body>
</html>
"""
class DTMLTopic(HelpTopic):
......@@ -239,9 +243,13 @@ class STXTopic(TextTopic):
return self.htmlfile(self, REQUEST)
htmlfile = HTML("""\
<dtml-var standard_html_header>
<dtml-var obj fmt="structured-text">
<dtml-var standard_html_footer>""")
<html>
<head><title><dtml-var title_or_id></title>
</head>
<body bgcolor="#FFFFFF">
<dtml-var obj fmt="structured-text">
</body>
</html>""")
class ReSTTopic(TextTopic):
......@@ -261,9 +269,13 @@ class ReSTTopic(TextTopic):
return self.htmlfile(self, REQUEST)
htmlfile = HTML("""\
<dtml-var standard_html_header>
<dtml-var obj fmt="restructured-text">
<dtml-var standard_html_footer>""")
<html>
<head><title><dtml-var title_or_id></title>
</head>
<body bgcolor="#FFFFFF">
<dtml-var obj fmt="restructured-text">
</body>
</html>""")
class ImageTopic(HelpTopic):
......
......@@ -11,30 +11,24 @@
#
##############################################################################
"""DTML Document objects.
$Id$
"""
from sgmllib import SGMLParser
from urllib import quote
from AccessControl import getSecurityManager
from AccessControl.Permissions import change_dtml_methods
from AccessControl.Permissions import change_dtml_documents
from App.class_init import InitializeClass
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile
from App.special_dtml import HTML
from OFS.DTMLMethod import decapitate
from OFS.DTMLMethod import DTMLMethod
from webdav.common import rfc1123_date
from OFS.PropertyManager import PropertyManager
from webdav.Lockable import ResourceLockedError
from zExceptions.TracebackSupplement import PathTracebackSupplement
from zope.contenttype import guess_content_type
from ZPublisher.Converters import type_converters
from OFS.PropertyManager import PropertyManager
done='done'
done = 'done'
_marker = [] # Create a new marker object.
......@@ -42,10 +36,10 @@ class DTMLDocument(PropertyManager, DTMLMethod):
"""DTML Document objects are DocumentTemplate.HTML objects that act
as methods whose 'self' is the DTML Document itself."""
meta_type='DTML Document'
icon ='p_/dtmldoc'
meta_type = 'DTML Document'
icon = 'p_/dtmldoc'
manage_options=(
manage_options = (
DTMLMethod.manage_options[:2] +
PropertyManager.manage_options +
DTMLMethod.manage_options[2:]
......@@ -58,10 +52,13 @@ class DTMLDocument(PropertyManager, DTMLMethod):
or perms
for perms in DTMLMethod.__ac_permissions__])
def manage_edit(self,data,title,SUBMIT='Change',dtpref_cols='100%',
dtpref_rows='20',REQUEST=None):
"""
Replaces a Documents contents with Data, Title with Title.
def manage_edit(self, data, title,
SUBMIT='Change',
dtpref_cols='100%',
dtpref_rows='20',
REQUEST=None
):
""" Replace contents with 'data', title with 'title'.
The SUBMIT parameter is also used to change the size of the editing
area on the default Document edit screen. If the value is "Smaller",
......@@ -71,41 +68,45 @@ class DTMLDocument(PropertyManager, DTMLMethod):
"""
self._validateProxy(REQUEST)
if self._size_changes.has_key(SUBMIT):
return self._er(data,title,SUBMIT,dtpref_cols,dtpref_rows,REQUEST)
return self._er(data, title,
SUBMIT, dtpref_cols, dtpref_rows, REQUEST)
if self.wl_isLocked():
raise ResourceLockedError, (
raise ResourceLockedError(
'This document has been locked via WebDAV.')
self.title=str(title)
if type(data) is not type(''): data=data.read()
self.title = str(title)
if type(data) is not type(''):
data = data.read()
self.munge(data)
self.ZCacheable_invalidate()
if REQUEST:
message="Content changed."
return self.manage_main(self,REQUEST,manage_tabs_message=message)
message = "Content changed."
return self.manage_main(self, REQUEST, manage_tabs_message=message)
def manage_upload(self,file='', REQUEST=None):
"""Replace the contents of the document with the text in file."""
def manage_upload(self, file='', REQUEST=None):
""" Replace the contents of the document with the text in 'file'.
"""
self._validateProxy(REQUEST)
if self.wl_isLocked():
raise ResourceLockedError, (
raise ResourceLockedError(
'This document has been locked via WebDAV.')
if type(file) is not type(''):
if REQUEST and not file:
raise ValueError, 'No file specified'
file=file.read()
file = file.read()
self.munge(file)
self.ZCacheable_invalidate()
if REQUEST:
message="Content uploaded."
return self.manage_main(self,REQUEST,manage_tabs_message=message)
message = "Content uploaded."
return self.manage_main(self, REQUEST, manage_tabs_message=message)
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
"""Render the document given a client object, REQUEST mapping,
Response, and key word arguments."""
"""Render the document with the given client object.
o If supplied, use REQUEST mapping, Response, and key word arguments.
"""
if not self._cache_namespace_keys:
data = self.ZCacheable_get(default=_marker)
if data is not _marker:
......@@ -113,26 +114,27 @@ class DTMLDocument(PropertyManager, DTMLMethod):
return data
__traceback_supplement__ = (PathTracebackSupplement, self)
kw['document_id'] =self.getId()
kw['document_title']=self.title
kw['document_id'] = self.getId()
kw['document_title'] =self.title
if hasattr(self, 'aq_explicit'):
bself=self.aq_explicit
else: bself=self
bself = self.aq_explicit
else:
bself = self
security=getSecurityManager()
security = getSecurityManager()
security.addContext(self)
try:
if client is None:
# Called as subtemplate, so don't need error propigation!
r=apply(HTML.__call__, (self, bself, REQUEST), kw)
r = apply(HTML.__call__, (self, bself, REQUEST), kw)
if RESPONSE is None: result = r
else: result = decapitate(r, RESPONSE)
if not self._cache_namespace_keys:
self.ZCacheable_set(result)
return result
r=apply(HTML.__call__, (self, (client, bself), REQUEST), kw)
r = apply(HTML.__call__, (self, (client, bself), REQUEST), kw)
if type(r) is not type('') or RESPONSE is None:
if not self._cache_namespace_keys:
self.ZCacheable_set(r)
......@@ -140,12 +142,12 @@ class DTMLDocument(PropertyManager, DTMLMethod):
finally: security.removeContext(self)
have_key=RESPONSE.headers.has_key
have_key = RESPONSE.headers.has_key
if not (have_key('content-type') or have_key('Content-Type')):
if self.__dict__.has_key('content_type'):
c=self.content_type
c = self.content_type
else:
c, e=guess_content_type(self.__name__, r)
c, e = guess_content_type(self.__name__, r)
RESPONSE.setHeader('Content-Type', c)
result = decapitate(r, RESPONSE)
if not self._cache_namespace_keys:
......@@ -156,12 +158,16 @@ class DTMLDocument(PropertyManager, DTMLMethod):
InitializeClass(DTMLDocument)
default_dd_html="""<dtml-var standard_html_header>
<h2><dtml-var title_or_id></h2>
default_dd_html="""<html>
<head><title><dtml-var title_or_id></title>
</head>
<body bgcolor="#FFFFFF">
<h2><dtml-var title_or_id></h2>
<p>
This is the <dtml-var id> Document.
</p>
<dtml-var standard_html_footer>"""
</body>
</html>"""
addForm=DTMLFile('dtml/documentAdd', globals())
......@@ -169,16 +175,21 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
"""Add a DTML Document object with the contents of file. If
'file' is empty, default document text is used.
"""
if type(file) is not type(''): file=file.read()
if not file: file=default_dd_html
id=str(id)
title=str(title)
ob=DTMLDocument(file, __name__=id)
ob.title=title
id=self._setObject(id, ob)
if type(file) is not type(''):
file = file.read()
if not file:
file = default_dd_html
id =str(id)
title = str(title)
ob = DTMLDocument(file, __name__=id)
ob.title = title
id = self._setObject(id, ob)
if REQUEST is not None:
try: u=self.DestinationURL()
except: u=REQUEST['URL1']
if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
try:
u = self.DestinationURL()
except:
u = REQUEST['URL1']
if submit == " Add and Edit ":
u = "%s/%s" % (u,quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''
This diff is collapsed.
......@@ -15,9 +15,32 @@ class DTMLDocumentTests(unittest.TestCase):
verifyClass(IWriteLock, self._getTargetClass())
class FactoryTests(unittest.TestCase):
def test_defaults_no_standard_html_header(self):
# see LP #496961
from OFS.DTMLDocument import addDTMLDocument
from OFS.DTMLDocument import DTMLDocument
dispatcher = DummyDispatcher()
addDTMLDocument(dispatcher, 'id')
method = dispatcher._set['id']
self.failUnless(isinstance(method, DTMLDocument))
self.failIf('standard_html_header' in method.read())
self.failIf('standard_html_footer' in method.read())
class DummyDispatcher:
def __init__(self):
self._set = {}
def _setObject(self, key, value):
self._set[key] = value
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DTMLDocumentTests),
unittest.makeSuite(FactoryTests),
))
if __name__ == '__main__':
......
......@@ -15,9 +15,33 @@ class DTMLMethodTests(unittest.TestCase):
verifyClass(IWriteLock, self._getTargetClass())
class FactoryTests(unittest.TestCase):
def test_defaults_no_standard_html_header(self):
# see LP #496961
from OFS.DTMLMethod import addDTMLMethod
from OFS.DTMLMethod import DTMLMethod
dispatcher = DummyDispatcher()
addDTMLMethod(dispatcher, 'id')
method = dispatcher._set['id']
self.failUnless(isinstance(method, DTMLMethod))
self.failIf('standard_html_header' in method.read())
self.failIf('standard_html_footer' in method.read())
class DummyDispatcher:
def __init__(self):
self._set = {}
def _setObject(self, key, value):
self._set[key] = value
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DTMLMethodTests),
unittest.makeSuite(FactoryTests),
))
if __name__ == '__main__':
......
......@@ -79,8 +79,9 @@ def manage_addZSearch(self, report_id, report_title, report_style,
self.manage_addDocument(
report_id,report_title,
('<dtml-var standard_html_header>\n%s\n'
'<dtml-var standard_html_footer>' %
('<html><head><title><dtml-var title_or_id></title>'
'</head><body bgcolor="#FFFFFF">\n%s\n'
'</body></html>' %
join(map(lambda q, report_style=report_style:
custom_default_report(q.id, q, no_table=report_style), qs),
'\n<hr>\n')))
......@@ -166,7 +167,8 @@ def default_input_form(arguments,action='query',
items=arguments.items()
return (
"%s\n%s%s" % (
'<dtml-var standard_html_header>\n%s\n'
'<html><head><title><dtml-var title_or_id></title>'
'</head><body bgcolor="#FFFFFF">\n%s\n'
'<form action="%s" method="get">\n'
'<h2><dtml-var document_title></h2>\n'
'Enter query parameters:<br>'
......@@ -193,18 +195,19 @@ def default_input_form(arguments,action='query',
'\n<tr><td colspan=2 align=center>\n'
'<input type="SUBMIT" name="SUBMIT" value="Submit Query">\n'
'</td></tr>\n</table>\n</form>\n'
'<dtml-var standard_html_footer>\n'
'</body></html>\n'
)
)
else:
return (
'<dtml-var standard_html_header>\n%s\n'
'<html><head><title><dtml-var title_or_id></title>'
'</head><body bgcolor="#FFFFFF">\n%s\n'
'<form action="%s" method="get">\n'
'<h2><dtml-var document_title></h2>\n'
'This query requires no input.<p>\n'
'<input type="SUBMIT" name="SUBMIT" value="Submit Query">\n'
'</form>\n'
'<dtml-var standard_html_footer>\n'
'</body></html>\n'
% (tabs, action)
)
......
......@@ -245,8 +245,9 @@ def upload_html(object, f):
body = ("<!--#var standard_html_header-->\n\n" +
body + "\n\n<!--#var standard_html_footer-->")
else:
body = ("<dtml-var standard_html_header>\n\n" +
body + "\n\n<dtml-var standard_html_footer>")
body = ("<html><head><title><dtml-var title_or_id></title>
</head><body bgcolor="#FFFFFF">\n\n" +
body + "\n\n</body></html>")
else:
if old: f=f.read()
......
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