Skip to content

Commit

Permalink
Merge 845fbe7 into 1808232
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Jun 17, 2020
2 parents 1808232 + 845fbe7 commit aafe767
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,9 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
4.4.4 (unreleased)
------------------

- Fix ``default`` keyword handling in page templates
(`#846 <https://github.com/zopefoundation/Zope/issues/846>`_)

- Update dependencies to newest bugfix releases.


Expand Down
13 changes: 12 additions & 1 deletion src/Products/PageTemplates/engine.py
Expand Up @@ -328,7 +328,18 @@ def __call__(self, context, macros, tal=True, **options):
kwargs["__zt_engine__"] = self.engine
kwargs["__zt_context__"] = context

return self.template.render(**kwargs)
template = self.template
# work around ``https://github.com/zopefoundation/Zope/issues/846``
template.cook_check() # ensure `_render` is computed
rf = getattr(template, "_render", None)
if rf is not None:
defs = [c for c in rf.__code__.co_consts if c == '__default']
if len(defs) == 1:
# use the template's private ``default`` representation
# as our TALES ``default`` value
kwargs["default"] = defs[0]

return template.render(**kwargs)

@classmethod
def cook(cls, source_file, text, engine, content_type):
Expand Down
8 changes: 8 additions & 0 deletions src/Products/PageTemplates/tests/input/Default.html
@@ -0,0 +1,8 @@
<html>
<head></head>
<body>
<p tal:define="foo string:"
tal:content="python: foo or default">Default in Python expression</p>
<p tal:content="context/I_Fail|default">Default in Path expression</p>
</body>
</html>
7 changes: 7 additions & 0 deletions src/Products/PageTemplates/tests/output/Default.html
@@ -0,0 +1,7 @@
<html>
<head></head>
<body>
<p>Default in Python expression</p>
<p>Default in Path expression</p>
</body>
</html>
3 changes: 3 additions & 0 deletions src/Products/PageTemplates/tests/testHTMLTests.py
Expand Up @@ -189,3 +189,6 @@ def testBadExpression(self):

def testPathAlternativesWithSpaces(self):
self.assert_expected(self.folder.t, 'PathAlternativesWithSpaces.html')

def testDefaultKeywordHandling(self):
self.assert_expected(self.folder.t, 'Default.html')

0 comments on commit aafe767

Please sign in to comment.