Skip to content

Commit

Permalink
Fix drop collection into caroussel tile
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Feb 29, 2016
1 parent ebc1775 commit 5f4442f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ There's a frood who really knows where his towel is.
1.0a13 (unreleased)
^^^^^^^^^^^^^^^^^^^

- Accept collection and folder objects into carousel tile (closes `574`_).
[rodfersou]

- Shows message to user if an exception is thrown in a tile (closes `#581`_).
[idgserpro]

Expand Down Expand Up @@ -737,6 +740,7 @@ There's a frood who really knows where his towel is.
.. _`#534`: https://github.com/collective/collective.cover/issues/534
.. _`#543`: https://github.com/collective/collective.cover/issues/543
.. _`#559`: https://github.com/collective/collective.cover/issues/559
.. _`#574`: https://github.com/collective/collective.cover/issues/574
.. _`#581`: https://github.com/collective/collective.cover/issues/581
.. _`#584`: https://github.com/collective/collective.cover/issues/584
.. _`PloneFormGen`: https://pypi.python.org/pypi/Products.PloneFormGen
44 changes: 44 additions & 0 deletions src/collective/cover/tests/test_carousel_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,34 @@
from collective.cover.tiles.carousel import ICarouselTile
from collective.cover.tiles.carousel import UUIDSFieldDataConverter
from collective.cover.widgets.textlinessortable import TextLinesSortableWidget
from plone import api
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID

import unittest


zptlogo = (
'GIF89a\x10\x00\x10\x00\xd5\x00\x00\xff\xff\xff\xff\xff\xfe\xfc\xfd\xfd'
'\xfa\xfb\xfc\xf7\xf9\xfa\xf5\xf8\xf9\xf3\xf6\xf8\xf2\xf5\xf7\xf0\xf4\xf6'
'\xeb\xf1\xf3\xe5\xed\xef\xde\xe8\xeb\xdc\xe6\xea\xd9\xe4\xe8\xd7\xe2\xe6'
'\xd2\xdf\xe3\xd0\xdd\xe3\xcd\xdc\xe1\xcb\xda\xdf\xc9\xd9\xdf\xc8\xd8\xdd'
'\xc6\xd7\xdc\xc4\xd6\xdc\xc3\xd4\xda\xc2\xd3\xd9\xc1\xd3\xd9\xc0\xd2\xd9'
'\xbd\xd1\xd8\xbd\xd0\xd7\xbc\xcf\xd7\xbb\xcf\xd6\xbb\xce\xd5\xb9\xcd\xd4'
'\xb6\xcc\xd4\xb6\xcb\xd3\xb5\xcb\xd2\xb4\xca\xd1\xb2\xc8\xd0\xb1\xc7\xd0'
'\xb0\xc7\xcf\xaf\xc6\xce\xae\xc4\xce\xad\xc4\xcd\xab\xc3\xcc\xa9\xc2\xcb'
'\xa8\xc1\xca\xa6\xc0\xc9\xa4\xbe\xc8\xa2\xbd\xc7\xa0\xbb\xc5\x9e\xba\xc4'
'\x9b\xbf\xcc\x98\xb6\xc1\x8d\xae\xbaFgs\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
'\x00,\x00\x00\x00\x00\x10\x00\x10\x00\x00\x06z@\x80pH,\x12k\xc8$\xd2f\x04'
'\xd4\x84\x01\x01\xe1\xf0d\x16\x9f\x80A\x01\x91\xc0ZmL\xb0\xcd\x00V\xd4'
'\xc4a\x87z\xed\xb0-\x1a\xb3\xb8\x95\xbdf8\x1e\x11\xca,MoC$\x15\x18{'
'\x006}m\x13\x16\x1a\x1f\x83\x85}6\x17\x1b $\x83\x00\x86\x19\x1d!%)\x8c'
'\x866#\'+.\x8ca`\x1c`(,/1\x94B5\x19\x1e"&*-024\xacNq\xba\xbb\xb8h\xbeb'
'\x00A\x00;'
)


class CarouselTileTestCase(TestTileMixin, unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -233,3 +255,25 @@ def test_get_alt(self):
self.assertIn('<img ', rendered)
self.assertIn(
'alt="This image was created for testing purposes"', rendered)

def test_populate_collection(self):
with api.env.adopt_roles(['Manager']):
api.content.create(
self.portal, 'News Item', id='new1', image=zptlogo)
api.content.create(
self.portal, 'News Item', id='new2', image=zptlogo)
api.content.create(
self.portal, 'News Item', id='new3', image=zptlogo)
query = [dict(
i='portal_type',
o='plone.app.querystring.operation.selection.is',
v='News Item',
)]
col = api.content.create(
self.portal, 'Collection', 'collection', query=query)
api.content.transition(col, 'publish')
self.tile.populate_with_object(col)
rendered = self.tile()
self.assertIn(u'<img src="http://nohost/plone/new1', rendered)
self.assertIn(u'<img src="http://nohost/plone/new2', rendered)
self.assertIn(u'<img src="http://nohost/plone/new3', rendered)
13 changes: 10 additions & 3 deletions src/collective/cover/tiles/carousel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
from collective.cover import _
from collective.cover.interfaces import ICoverUIDsProvider
from collective.cover.interfaces import ITileEditForm
from collective.cover.tiles.list import IListTile
from collective.cover.tiles.list import ListTile
from collective.cover.widgets.interfaces import ITextLinesSortableWidget
from collective.cover.widgets.textlinessortable import TextLinesSortableFieldWidget
from plone import api
from plone.app.uuid.utils import uuidToObject
from plone.autoform import directives as form
from plone.tiles.interfaces import ITileDataManager
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
Expand Down Expand Up @@ -64,9 +66,14 @@ def populate_with_object(self, obj):
:param uuids: The list of objects' UUIDs to be used
:type uuids: List of strings
"""
if not self._has_image_field(obj):
return
super(CarouselTile, self).populate_with_object(obj)
# check permission
super(ListTile, self).populate_with_object(obj) # check permission
uuids = ICoverUIDsProvider(obj).getUIDs()
uuids = [
uuid for uuid in uuids
if self._has_image_field(uuidToObject(uuid))]
if uuids:
self.populate_with_uuids(uuids)

def autoplay(self):
if self.data['autoplay'] is None:
Expand Down

0 comments on commit 5f4442f

Please sign in to comment.