Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed May 29, 2017
1 parent d4dca61 commit 504251c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 82 deletions.
15 changes: 11 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ There's a frood who really knows where his towel is.
1.4b2 (unreleased)
^^^^^^^^^^^^^^^^^^

- Enable collection and folders to be listed at tile list;
Tile carousel don't accept folder anymore;
Removed adapter to handle content dropped at tile list as it don't make sense anymore. (closes `#713`_).
[rodfersou]
.. Warning::
Adapters used to get the items inside a folder or the results of the query in a collection were deprecated.
The following classes will be removed in collective.cover v1.7: ``ICoverUIDsProvider``, ``CollectionUIDsProvider``, ``FolderUIDsProvider`` and ``GenericUIDsProvider``.

- Dropping a folder on a carousel tile no longer populates the tile with the items inside the folder;
populating the carousel tile with the results of the query in a collection is still supported.
[rodfersou, hvelarde]

- Dropping a folder or a collection into a list tile previously resulted in the tile being populated with the items inside the folder or the results of the query in the collection,
making impossible to have folders or collection as items of the list tile themselves (fixes `#713`_).
[rodfersou, hvelarde]

- Fix order of uuids of sorted function in ListTile's 'results' method.
[idgserpro]
Expand Down
8 changes: 4 additions & 4 deletions docs/end-user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ item will show an image, title and description. Carousel tiles are 100%
responsive, support native-like swipe movements and use hardware optimized
animations.

You just can't drop a Folder into a Carousel tile; other objects are allowed.
You can drop any object with an image into a Carousel tile.
Besides that, if you drop a collection into this tile,
it will take every item in the query result and insert it into the carousel until it reaches the max items specified in the configuration.

You can edit the metadata (title, description and URL) of items in the carousel,
and you can reorder or remove them from the tile.
You can also specify if the carousel will start playing the slideshow automatically or not.
Every item in the slideshow will have a link pointing back to the original object.

If you drop a collection into this tile,
it will take every item into the collection and insert it until it reaches the max items specified into configuration.

Carousel tile is fully responsive, so be sure to configure it to use the image size that fits better the maximum desired size.

Collection
Expand Down
13 changes: 3 additions & 10 deletions src/collective/cover/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from plone.supermodel import model
from zope.deprecation import deprecate
from zope.interface import Attribute
from zope.interface import Interface

Expand Down Expand Up @@ -31,15 +30,9 @@ def getSearchResults(self, filter_portal_types, rooted, document_base_url, searc


class ICoverUIDsProvider(Interface):

@deprecate('Adapter deprecated')
def getUIDs(self):
"""Get UUIDs associated with the object.
could be the UUID of the object or a
list of related UUIDs.
@return: iterable of UUIDs
"""
"""XXX: ICoverUIDsProvider interface is deprecated and will be
removed in collective.cover v1.7.
"""


class ITileEditForm(Interface):
Expand Down
36 changes: 16 additions & 20 deletions src/collective/cover/tests/test_carousel_tile.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from collective.cover.controlpanel import ICoverSettings
from collective.cover.testing import ALL_CONTENT_TYPES
from collective.cover.tests.base import TestTileMixin
from collective.cover.tiles.carousel import CarouselTile
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.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from zope.component import getUtility

import unittest

Expand Down Expand Up @@ -39,14 +37,7 @@ def test_default_configuration(self):
self.assertTrue(self.tile.is_editable)

def test_accepted_content_types(self):
# Add folder to default accepted_ct
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings.searchable_content_types += ['Folder']
self.assertNotIn('Folder', self.tile.accepted_ct())

expected = ['Document', 'Image', 'Collection', 'Link', 'File', 'News Item']
self.assertEqual(self.tile.accepted_ct(), expected)
self.assertEqual(self.tile.accepted_ct(), ALL_CONTENT_TYPES)

def test_tile_is_empty(self):
self.assertTrue(self.tile.is_empty())
Expand Down Expand Up @@ -245,26 +236,31 @@ def test_get_alt(self):
'alt="This image was created for testing purposes"', rendered)

def test_populate_with_collection(self):
"""Populating a carousel tile with a collection should result on
the tile being populated with the results that have an image
field.
"""
from collective.cover.testing import zptlogo
from collective.cover.tests.utils import set_image_field
with api.env.adopt_roles(['Manager']):
api.content.create(self.portal, 'News Item', id='new1')
api.content.create(self.portal, 'News Item', id='new2')
api.content.create(self.portal, 'News Item', id='new3')
api.content.create(self.portal, 'News Item', id='item1')
api.content.create(self.portal, 'News Item', id='item2')
api.content.create(self.portal, 'News Item', id='item3')
# handle Archetypes and Dexterity
set_image_field(self.portal['new1'], zptlogo)
set_image_field(self.portal['new2'], zptlogo)
set_image_field(self.portal['item1'], zptlogo)
set_image_field(self.portal['item2'], 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)
self.portal, 'Collection', id='collection', query=query)

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.assertNotIn(u'<img src="http://nohost/plone/new3', rendered)
self.assertNotIn(u'<img src="http://nohost/plone/folder', rendered)
self.assertIn(u'<img src="http://nohost/plone/item1', rendered)
self.assertIn(u'<img src="http://nohost/plone/item2', rendered)
self.assertNotIn(u'<img src="http://nohost/plone/item3', rendered)
43 changes: 15 additions & 28 deletions src/collective/cover/tests/test_list_tile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from collective.cover.controlpanel import ICoverSettings
from collective.cover.testing import ALL_CONTENT_TYPES
from collective.cover.testing import zptlogo
from collective.cover.tests.base import TestTileMixin
from collective.cover.tests.utils import set_image_field
from collective.cover.tests.utils import today
from collective.cover.tiles.list import IListTile
from collective.cover.tiles.list import ListTile
Expand All @@ -10,10 +11,8 @@
from plone.app.testing import login
from plone.app.testing import logout
from plone.app.testing import TEST_USER_NAME
from plone.registry.interfaces import IRegistry
from plone.tiles.interfaces import ITileDataManager
from plone.uuid.interfaces import IUUID
from zope.component import getUtility

import unittest

Expand Down Expand Up @@ -265,45 +264,33 @@ def test_thumbnail_original_image(self):
self.assertIsInstance(self.tile(), unicode)

def test_populate_with_collection(self):
from collective.cover.testing import zptlogo
from collective.cover.tests.utils import set_image_field
with api.env.adopt_roles(['Manager']):
api.content.create(self.portal, 'News Item', id='new1')
api.content.create(self.portal, 'News Item', id='new2')
api.content.create(self.portal, 'News Item', id='new3')
api.content.create(self.portal, 'News Item', id='item')
# handle Archetypes and Dexterity
set_image_field(self.portal['new1'], zptlogo)
set_image_field(self.portal['new2'], zptlogo)
set_image_field(self.portal['item'], 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)
collection = api.content.create(
self.portal, 'Collection', id='collection', query=query)

self.tile.populate_with_object(col)
self.tile.populate_with_object(collection)
rendered = self.tile()
self.assertIn(u'<h2><a href="http://nohost/plone/collection', rendered)
self.assertIn(u'<a href="http://nohost/plone/collection"></a>', rendered)
self.assertNotIn(u'<a href="http://nohost/plone/item"></a>', rendered)

def test_populate_with_folder(self):
# Add folder to default accepted_ct
registry = getUtility(IRegistry)
settings = registry.forInterface(ICoverSettings)
settings.searchable_content_types += ['Folder']

from collective.cover.testing import zptlogo
from collective.cover.tests.utils import set_image_field
with api.env.adopt_roles(['Manager']):
folder = api.content.create(self.portal, 'Folder', id='folder')
api.content.create(folder, 'News Item', id='new1')
api.content.create(folder, 'News Item', id='new2')
api.content.create(folder, 'News Item', id='new3')
api.content.create(self.portal, 'News Item', id='item')
# handle Archetypes and Dexterity
set_image_field(folder['new1'], zptlogo)
set_image_field(folder['new2'], zptlogo)
set_image_field(self.portal['item'], zptlogo)

folder = api.content.create(self.portal, 'Folder', id='folder')

self.tile.populate_with_object(folder)
rendered = self.tile()
self.assertIn(u'<h2><a href="http://nohost/plone/folder', rendered)
self.assertIn(u'<a href="http://nohost/plone/folder"></a>', rendered)
self.assertNotIn(u'<a href="http://nohost/plone/item"></a>', rendered)
9 changes: 1 addition & 8 deletions src/collective/cover/tiles/carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from collective.cover.widgets.textlinessortable import TextLinesSortableFieldWidget
from plone.app.uuid.utils import uuidToObject
from plone.autoform import directives as form
from plone.memoize import view
from plone.tiles.interfaces import ITileDataManager
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from z3c.form.converter import BaseDataConverter
Expand Down Expand Up @@ -66,7 +65,7 @@ def populate_with_object(self, obj):
:type uuids: List of strings
"""
super(ListTile, self).populate_with_object(obj) # check permission
if obj.portal_type in ('Topic', 'Collection'):
if obj.portal_type == 'Collection':
uuids = [i.UID for i in obj.queryCatalog()]
else:
uuids = [self.get_uuid(obj)]
Expand All @@ -75,12 +74,6 @@ def populate_with_object(self, obj):
if uuids:
self.populate_with_uuids(uuids)

@view.memoize
def accepted_ct(self):
"""Return all content types available (default value)."""
cts = set(super(CarouselTile, self).accepted_ct())
return list(cts - frozenset(['Folder']))

def autoplay(self):
if self.data['autoplay'] is None:
return True # default value
Expand Down
40 changes: 32 additions & 8 deletions src/collective/cover/tiles/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from AccessControl import Unauthorized
from collective.cover import _
from collective.cover.config import PROJECTNAME
from collective.cover.interfaces import ICoverUIDsProvider
from collective.cover.interfaces import ITileEditForm
from collective.cover.tiles.base import IPersistentCoverTile
from collective.cover.tiles.base import PersistentCoverTile
Expand Down Expand Up @@ -250,7 +249,6 @@ def remove_item(self, uuid):
old_data['uuids'] = uuids
data_mgr.set(old_data)

@view.memoize
def get_uuid(self, obj):
"""Return the UUID of the object.
Expand Down Expand Up @@ -377,14 +375,40 @@ def get_title_tag(self, item):
return self._get_title_tag(item)


@implementer(ICoverUIDsProvider)
class CollectionUIDsProvider(object):

MSG = 'CollectionUIDsProvider adapter is deprecated and will be removed in collective.cover v1.7.'

@deprecate(MSG)
def __init__(self, context):
pass

@deprecate(MSG)
def getUIDs(self):
pass


class FolderUIDsProvider(object):

MSG = 'FolderUIDsProvider adapter is deprecated and will be removed in collective.cover v1.7.'

@deprecate(MSG)
def __init__(self, context):
pass

@deprecate(MSG)
def getUIDs(self):
pass


class GenericUIDsProvider(object):

@deprecate('Adapter deprecated')
MSG = 'GenericUIDsProvider adapter is deprecated and will be removed in collective.cover v1.7.'

@deprecate(MSG)
def __init__(self, context):
self.context = context
pass

@deprecate('Adapter deprecated')
@deprecate(MSG)
def getUIDs(self):
"""Return a list of UUIDs of collection objects."""
return [IUUID(self.context)]
pass

0 comments on commit 504251c

Please sign in to comment.