Skip to content

Commit

Permalink
Merge 0aeaa53 into 6ffee54
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTango committed Jul 2, 2019
2 parents 6ffee54 + 0aeaa53 commit c42fcc0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ local/
parts/
var/
src/
/pip-selfcheck.json
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
------------------

Bug fixes:
- Catch errors on resolving tiles and return an error message instead of breaking the whole UI
[MrTango]

- Fix issue where layout aware tile data storage read cache was not purged when
data was updated programmatically [fixes #75]
Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[buildout]
extends =
test-x.x.x.cfg
test-5.2.x.cfg

package-name = plone.app.blocks
package-extras = [test]
Expand Down
13 changes: 11 additions & 2 deletions plone/app/blocks/tests/test_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
import unittest


try:
# Python 2: "unicode" is built-in
unicode
except NameError:
unicode = str


class ITestTile(Interface):

magicNumber = schema.Int(title=u"Magic number", required=False)
Expand All @@ -35,6 +42,7 @@ def __call__(self):
<p>
Magic number: %(number)d; Form: %(form)s;
Query string: %(queryString)s; URL: %(url)s
Umlauts: Übertile ;)
</p>
</body>
</html>""" % dict(name=self.id, number=self.data['magicNumber'] or -1,
Expand Down Expand Up @@ -221,10 +229,11 @@ def testRenderTiles(self):
request = self.layer['request']
tree = serializer.tree
renderTiles(request, tree)
result = str(serializer)
result = unicode(serializer)
self.assertIn('This is a demo tile with id tile2', result)
self.assertIn('This is a demo tile with id tile3', result)
self.assertIn('This is a demo tile with id tile4', result)
self.assertIn(u'Umlauts: \xdcbertile', result)

def testRenderTilesError(self):
serializer = getHTMLSerializer([testLayout2])
Expand All @@ -234,7 +243,7 @@ def testRenderTilesError(self):
result = str(serializer)
self.assertIn('This is a demo tile with id tile2', result)
self.assertNotIn('This is a demo tile with id tile3', result)
self.assertIn('There was an error while rendering this tile', result)
self.assertIn('There was an error', result)
self.assertIn('This is a demo tile with id tile4', result)

def testRenderSubTiles(self):
Expand Down
26 changes: 24 additions & 2 deletions plone/app/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,31 @@ def extractCharset(response, default='utf-8'):
def resolve(url, resolved=None):
"""Resolve the given URL to an lxml tree.
"""

if resolved is None:
resolved = resolveResource(url)
try:
resolved = resolveResource(url)
except Exception:
logger.exception(
'There was an error while resolving the tile: {0}'.format(
url,
),
)
scheme, netloc, path, params, query, fragment = parse.urlparse(url)
tile_parts = {
'scheme': scheme,
'netloc': netloc,
'path': path,
}
resolved = """<html>
<body>
<dl class="portalMessage error" role="alert">
<dt>Error</dt>
<dd>There was an error while resolving the tile {scheme}://{netloc}{path}</dd>
</dl>
</body>
</html>
""".format(**tile_parts)

if not resolved.strip():
return None
try:
Expand Down
10 changes: 9 additions & 1 deletion test-5.2.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ parts +=
createcoverage

extensions = mr.developer
auto-checkout =
auto-checkout = plone.subrequest

[remotes]
plone = https://github.com/plone
plone-push = git+ssh://git@github.com/plone
collective = https://github.com/collective
collective-push = git+ssh://git@github.com/collective

[sources]
plone.subrequest = git ${remotes:plone}/plone.subrequest.git pushurl=${remotes:plone-push}/plone.subrequest.git


[versions]
setuptools =
Expand Down

0 comments on commit c42fcc0

Please sign in to comment.