Skip to content

Commit

Permalink
Merge branch 'master' into issue_490
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Feb 17, 2019
2 parents 7716aeb + a82fb27 commit 562ea0b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 24 deletions.
14 changes: 14 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ https://github.com/zopefoundation/Zope/blob/4.0a6/CHANGES.rst
Fixes
+++++

- Fix subscript access on Page Template ``macros`` attribute
(`#210 <https://github.com/zopefoundation/Zope/issues/210>`_)

- Fix ``OFS.interfaces`` attribute declarations to match reality
(`#498 <https://github.com/zopefoundation/Zope/issues/498`_)

Expand All @@ -23,6 +26,17 @@ Fixes
- Fix error when not selecting a file for upload in Files and Images
(`#492 <https://github.com/zopefoundation/Zope/issues/492>`_)

- Fix ZMI add handling of ``len(filtered_meta_types()) == 1``
(`#505 <https://github.com/zopefoundation/Zope/issues/505>`_)

- Fix ZMI add handling of ``addItemSelect`` form
(`#506 <https://github.com/zopefoundation/Zope/issues/506>`_)

Other changes
+++++++++++++
- Make sure the WSGI Response object respects lock semantics
(`#216 <https://github.com/zopefoundation/Zope/issues/216>`_)


4.0b9 (2019-02-09)
------------------
Expand Down
10 changes: 4 additions & 6 deletions src/App/dtml/manage_navbar.dtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<i class="fa fa-cog"></i> <span class="zmi-label">Control&nbsp;Panel</span>
</a>
</li>
<dtml-if filtered_meta_types>
<dtml-if "aq_explicit"><dtml-if "hasattr(aq_explicit, 'filtered_meta_types')">
<li class="form-inline zmi-addItemSelect">
<form method="get" class="form-group">
<label for="addItemSelect" class="ml-2 sr-only">Select type to add</label>
Expand All @@ -41,16 +41,14 @@
title="Select type to add"
onchange="addItem( elm=this, base_url='<dtml-var "REQUEST.get('URL1','')">'); this.selectedIndex = 0;"
><option value="" selected="selected">Select type to add</option>
<dtml-if "_.len(filtered_meta_types) > 1"
><dtml-in filtered_meta_types mapping sort=name
<dtml-in filtered_meta_types mapping sort=name
><dtml-if action><option value="&dtml.html_quote-action;">&dtml-name;</option>
</dtml-if
></dtml-in
></dtml-if>
></dtml-in>
</select>
</form>
</li>
</dtml-if>
</dtml-if></dtml-if>
</ul>

<a href="manage_zmi_logout" title="Logout"
Expand Down
5 changes: 5 additions & 0 deletions src/Products/PageTemplates/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from chameleon.tales import StringExpr
from chameleon.tales import NotExpr
from chameleon.tal import RepeatDict
from chameleon.zpt.template import Macros

from z3c.pt.expressions import PythonExpr, ProviderExpr

Expand All @@ -33,6 +34,10 @@

InitializeClass(RepeatDict)

# Declare Chameleon Macros object accessible
# This makes subscripting work, as in template.macros['name']
Macros.__allow_access_to_unprotected_subobjects__ = True

re_match_pi = re.compile(r'<\?python([^\w].*?)\?>', re.DOTALL)
logger = logging.getLogger('Products.PageTemplates')

Expand Down
1 change: 1 addition & 0 deletions src/Products/PageTemplates/tests/macros.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<i metal:define-macro="foo">bar</i><i metal:use-macro="template/macros/foo" /><i metal:use-macro="python:template.macros['foo']" />
21 changes: 21 additions & 0 deletions src/Products/PageTemplates/tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ def test_zopepagetemplate_processing_instruction_skipped(self):
template.write(data)
self.assertIn('world', template())

def test_macros_access(self):
from Products.PageTemplates.ZopePageTemplate import \
manage_addPageTemplate
from zExceptions import Unauthorized
template = manage_addPageTemplate(self.folder, 'test')

# aq-wrap before we proceed
template = template.__of__(self.folder)

# test rendering engine
with open(os.path.join(path, "macros.pt")) as fd:
data = fd.read()
template.write(data)
try:
output = template()
raised = False
except Unauthorized:
raised = True
self.assertFalse(raised, 'Unauthorized exception raised')
self.assertIn('<i>bar</i><i>bar</i><i>bar</i>', output)


def test_suite():
return unittest.TestSuite((
Expand Down
9 changes: 9 additions & 0 deletions src/ZPublisher/HTTPResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,10 @@ def write(self, data):
self.stdout.write(data)

def setBody(self, body, title='', is_error=False, lock=None):
# allow locking of the body in the same way as the status
if self._locked_body:
return

if isinstance(body, IOBase):
body.seek(0, 2)
length = body.tell()
Expand All @@ -1081,6 +1085,11 @@ def setBody(self, body, title='', is_error=False, lock=None):
else:
super(WSGIResponse, self).setBody(body, title, is_error)

# Have to apply the lock at the end in case the super class setBody
# is called, which will observe the lock and do nothing
if lock:
self._locked_body = 1

def __bytes__(self):
raise NotImplementedError

Expand Down
12 changes: 7 additions & 5 deletions src/ZPublisher/WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ def transaction_pubevents(request, response, tm=transaction.manager):
response._unauthorized()
response.setStatus(exc.getStatus())

notify(pubevents.PubBeforeAbort(
request, exc_info, request.supports_retry()))
retry = False
if isinstance(exc, TransientError) and request.supports_retry():
retry = True

notify(pubevents.PubBeforeAbort(request, exc_info, retry))
tm.abort()
notify(pubevents.PubFailure(
request, exc_info, request.supports_retry()))
notify(pubevents.PubFailure(request, exc_info, retry))

if isinstance(exc, TransientError) and request.supports_retry():
if retry:
reraise(*exc_info)

if not (exc_view_created or isinstance(exc, Unauthorized)):
Expand Down
7 changes: 7 additions & 0 deletions src/ZPublisher/tests/test_WSGIPublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ def __len__(self):
self.assertEqual(response.getHeader('Content-Length'),
'%d' % len(TestStreamIterator.data))

def test_setBody_w_locking(self):
response = self._makeOne()
response.setBody(b'BEFORE', lock=True)
result = response.setBody(b'AFTER')
self.assertFalse(result)
self.assertEqual(response.body, b'BEFORE')

def test___str___raises(self):
response = self._makeOne()
response.setBody('TESTING')
Expand Down
14 changes: 1 addition & 13 deletions src/zmi/styles/resources/zmi_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,7 @@ $(function() {
fix_ancient_gui();

// EXECUTE FUNCTIONAL WORKAROUNDS
// [1] Showing some Menu Elements only on List Page as Active
// List Page is assumed if the ZMI tabs contain a "manage_findForm"
// on folders or a "manage_catalogFind" on ZCatalogs
if ($('.nav a[href="manage_findForm"]').length > 0 || $('.nav a[href="manage_catalogFind"]').length > 0) {
$('#addItemSelect').removeClass('disabled');
$('#addItemSelect').removeAttr('disabled');
$('#addItemSelect').attr( 'title', $('#addItemSelect').attr('data-title-active') );
} else {
$('#addItemSelect').addClass('disabled');
$('#addItemSelect').attr('disabled','disabled');
$('#addItemSelect').attr( 'title', $('#addItemSelect').attr('data-title-inactive') );
}

// empty for the moment

if (!window.matchMedia || (window.matchMedia("(max-width: 767px)").matches)) {
$('.zmi header.navbar li.zmi-authenticated_user').tooltip({'placement':'bottom'});
Expand Down

0 comments on commit 562ea0b

Please sign in to comment.