Skip to content

Commit

Permalink
Merge pull request #28 from plone/issue_27
Browse files Browse the repository at this point in the history
Issue 27 - Don't make a tile exception break other tiles
  • Loading branch information
hvelarde committed Mar 28, 2016
2 parents 0bd4a33 + 92fd100 commit e61daf5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changelog

New:

- Don't make a tile exception break other tiles (closes `#27`_).
[rodfersou]

- Provide new getLayoutsFromDirectory utility to get layouts from any
plone.resource directory, not just the base resource directory

Expand Down Expand Up @@ -232,3 +235,5 @@ New:

- initial release.
[garbas]

.. _`#27`: https://github.com/plone/plone.app.blocks/issues/27
40 changes: 37 additions & 3 deletions plone/app/blocks/tests/test_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def setUpZope(self, app, configurationContext):
/>
<plone:tile
name="test.broken"
name="test.tile1.broken"
title="Broken Test Tile"
description=""
add_permission="cmf.ModifyPortalContent"
Expand All @@ -93,7 +93,7 @@ def setUpZope(self, app, configurationContext):
bases=(BLOCKS_TILES_FIXTURE,), name="Blocks:Tiles:Integration")


testLayout = """\
testLayout1 = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html data-layout="./@@default-site-layout">
<head></head>
Expand All @@ -116,16 +116,50 @@ def setUpZope(self, app, configurationContext):
"""


testLayout2 = """\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html data-layout="./@@default-site-layout">
<head></head>
<body>
<h1>Welcome!</h1>
<div data-panel="panel1">
Page panel 1
<div id="page-tile2" data-tile="./@@test.tile1/tile2?magicNumber:int=2">Page tile 2 placeholder</div>
</div>
<div data-panel="panel2">
Page panel 2
<div id="page-tile3" data-tile="./@@test.tile1.broken/tile3">Page tile 3 placeholder</div>
</div>
<div data-panel="panel4">
Page panel 4 (ignored)
<div id="page-tile4" data-tile="./@@test.tile1/tile4">Page tile 4 placeholder</div>
</div>
</body>
</html>
"""


class TestRenderTiles(unittest.TestCase):

layer = BLOCKS_TILES_INTEGRATION_TESTING

def testRenderTiles(self):
serializer = getHTMLSerializer([testLayout])
serializer = getHTMLSerializer([testLayout1])
request = self.layer['request']
tree = serializer.tree
renderTiles(request, tree)
result = serializer.serialize()
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)

def testRenderTilesError(self):
serializer = getHTMLSerializer([testLayout2])
request = self.layer['request']
tree = serializer.tree
renderTiles(request, tree)
result = serializer.serialize()
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('This is a demo tile with id tile4', result)
24 changes: 18 additions & 6 deletions plone/app/blocks/tiles.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# -*- coding: utf-8 -*-
from urlparse import urljoin

from plone.app.blocks import PloneMessageFactory
from plone.app.blocks import utils
from plone.app.blocks.interfaces import IBlocksSettings
from plone.app.blocks.utils import resolve_transform
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ESI_HEADER
from plone.tiles.interfaces import ESI_HEADER_KEY
from urlparse import urljoin
from zExceptions import NotFound
from zope.component import queryUtility
from zope.i18n import translate
from lxml import html

from plone.app.blocks.interfaces import IBlocksSettings
from plone.app.blocks import utils
from plone.app.blocks.utils import resolve_transform
from plone.tiles.interfaces import ESI_HEADER, ESI_HEADER_KEY

def errorTile(request):
msg = PloneMessageFactory('There was an error while rendering this tile')
translated = translate(msg, context=request)
return html.fromstring(translated).getroottree()


def renderTiles(request, tree):
Expand Down Expand Up @@ -36,6 +44,8 @@ def renderTiles(request, tree):
tileHref = urljoin(baseURL, tileHref)
try:
tileTree = utils.resolve(tileHref)
except RuntimeError:
tileTree = None
except NotFound:
continue
if tileTree is not None:
Expand All @@ -50,6 +60,8 @@ def renderTiles(request, tree):
tileHref = urljoin(baseURL, tileHref)
try:
tileTree = utils.resolve(tileHref)
except RuntimeError:
tileTree = errorTile(request)
except NotFound:
continue

Expand Down

0 comments on commit e61daf5

Please sign in to comment.