diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index 10e111d30..6d68fcf2c 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -4,6 +4,9 @@ There's a frood who really knows where his towel is 1.0a4 (unreleased) ^^^^^^^^^^^^^^^^^^ +- Add banner tile that will replace image and link tiles. (closes `#218`_). + [hvelarde] + - Refactor image tile to use original image and scales, when possible. [ericof, hvelarde] @@ -180,3 +183,4 @@ There's a frood who really knows where his towel is .. _`#191`: https://github.com/collective/collective.cover/issues/191 .. _`#198`: https://github.com/collective/collective.cover/issues/198 .. _`#206`: https://github.com/collective/collective.cover/issues/206 +.. _`#218`: https://github.com/collective/collective.cover/issues/218 diff --git a/src/collective/cover/locales/collective.cover.pot b/src/collective/cover/locales/collective.cover.pot index 4ff9b9f3e..d0e195254 100644 --- a/src/collective/cover/locales/collective.cover.pot +++ b/src/collective/cover/locales/collective.cover.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: collective.cover\n" -"POT-Creation-Date: 2013-05-29 21:16+0000\n" +"POT-Creation-Date: 2013-05-30 20:41+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -143,6 +143,10 @@ msgstr "" msgid "Drag&drop an image here to populate the tile." msgstr "" +#: collective/cover/tiles/templates/banner.pt:8 +msgid "Drag&drop an image or link here to populate the tile." +msgstr "" + #: collective/cover/layout_templates/tile.pt:47 msgid "Edit" msgstr "" @@ -180,9 +184,9 @@ msgstr "" msgid "HTML tag" msgstr "" +#: collective/cover/tiles/banner.py:23 #: collective/cover/tiles/basic.py:36 #: collective/cover/tiles/image.py:18 -#: collective/cover/tiles/link.py:27 msgid "Image" msgstr "" @@ -346,12 +350,13 @@ msgstr "" msgid "Tile saved" msgstr "" +#: collective/cover/tiles/banner.py:18 #: collective/cover/tiles/basic.py:26 #: collective/cover/tiles/embed.py:19 -#: collective/cover/tiles/file.py:41 msgid "Title" msgstr "" +#: collective/cover/tiles/banner.py:28 #: collective/cover/tiles/link.py:32 msgid "URL" msgstr "" diff --git a/src/collective/cover/locales/es/LC_MESSAGES/collective.cover.po b/src/collective/cover/locales/es/LC_MESSAGES/collective.cover.po index cbe121d26..da43cd3ba 100644 --- a/src/collective/cover/locales/es/LC_MESSAGES/collective.cover.po +++ b/src/collective/cover/locales/es/LC_MESSAGES/collective.cover.po @@ -3,8 +3,8 @@ msgid "" msgstr "" "Project-Id-Version: collective.cover\n" -"POT-Creation-Date: 2013-05-29 21:16+0000\n" -"PO-Revision-Date: 2013-05-29 18:19-0300\n" +"POT-Creation-Date: 2013-05-30 20:41+0000\n" +"PO-Revision-Date: 2013-05-30 17:42-0300\n" "Last-Translator: Héctor Velarde \n" "Language-Team: Spanish \n" "MIME-Version: 1.0\n" @@ -146,6 +146,10 @@ msgstr "Enlace de descarga" msgid "Drag&drop an image here to populate the tile." msgstr "Arrastre y suelte una imagen aquí." +#: collective/cover/tiles/templates/banner.pt:8 +msgid "Drag&drop an image or link here to populate the tile." +msgstr "Arrastre y suelte una imagen o un enlace aquí." + #: collective/cover/layout_templates/tile.pt:47 msgid "Edit" msgstr "Editar" @@ -183,9 +187,9 @@ msgstr "Filtrar elementos" msgid "HTML tag" msgstr "Tag HTML" +#: collective/cover/tiles/banner.py:23 #: collective/cover/tiles/basic.py:36 #: collective/cover/tiles/image.py:18 -#: collective/cover/tiles/link.py:27 msgid "Image" msgstr "Imagen" @@ -349,12 +353,13 @@ msgstr "Configuración del tile guardada." msgid "Tile saved" msgstr "Tile guardado" +#: collective/cover/tiles/banner.py:18 #: collective/cover/tiles/basic.py:26 #: collective/cover/tiles/embed.py:19 -#: collective/cover/tiles/file.py:41 msgid "Title" msgstr "Titulo" +#: collective/cover/tiles/banner.py:28 #: collective/cover/tiles/link.py:32 msgid "URL" msgstr "URL" diff --git a/src/collective/cover/locales/fr/LC_MESSAGES/collective.cover.po b/src/collective/cover/locales/fr/LC_MESSAGES/collective.cover.po index 0bd3406f1..e2b0926ba 100644 --- a/src/collective/cover/locales/fr/LC_MESSAGES/collective.cover.po +++ b/src/collective/cover/locales/fr/LC_MESSAGES/collective.cover.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: collective.cover\n" -"POT-Creation-Date: 2013-05-29 21:16+0000\n" +"POT-Creation-Date: 2013-05-30 20:41+0000\n" "PO-Revision-Date: 2013-05-29 18:20-0300\n" "Last-Translator: Héctor Velarde \n" "Language-Team: French \n" @@ -148,6 +148,10 @@ msgstr "Lien de téléchargement" msgid "Drag&drop an image here to populate the tile." msgstr "Veuillez glisser & déposer une image ici (via le bouton 'Ajouter du contenu')" +#: collective/cover/tiles/templates/banner.pt:8 +msgid "Drag&drop an image or link here to populate the tile." +msgstr "" + #: collective/cover/layout_templates/tile.pt:47 msgid "Edit" msgstr "Modifier" @@ -185,9 +189,9 @@ msgstr "Filtrer les éléments" msgid "HTML tag" msgstr "Balise HTML" +#: collective/cover/tiles/banner.py:23 #: collective/cover/tiles/basic.py:36 #: collective/cover/tiles/image.py:18 -#: collective/cover/tiles/link.py:27 msgid "Image" msgstr "Image" @@ -351,12 +355,13 @@ msgstr "Configuration de la tuile enregistrée." msgid "Tile saved" msgstr "Tuile enregistrée" +#: collective/cover/tiles/banner.py:18 #: collective/cover/tiles/basic.py:26 #: collective/cover/tiles/embed.py:19 -#: collective/cover/tiles/file.py:41 msgid "Title" msgstr "Titre" +#: collective/cover/tiles/banner.py:28 #: collective/cover/tiles/link.py:32 msgid "URL" msgstr "URL" diff --git a/src/collective/cover/locales/pt_BR/LC_MESSAGES/collective.cover.po b/src/collective/cover/locales/pt_BR/LC_MESSAGES/collective.cover.po index 8a3f604f5..ca77fb2eb 100644 --- a/src/collective/cover/locales/pt_BR/LC_MESSAGES/collective.cover.po +++ b/src/collective/cover/locales/pt_BR/LC_MESSAGES/collective.cover.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: collective.cover\n" -"POT-Creation-Date: 2013-05-29 21:16+0000\n" -"PO-Revision-Date: 2013-05-29 18:19-0300\n" +"POT-Creation-Date: 2013-05-30 20:41+0000\n" +"PO-Revision-Date: 2013-05-30 17:46-0300\n" "Last-Translator: Héctor Velarde \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" @@ -141,7 +141,11 @@ msgstr "Link para download" #: collective/cover/tiles/templates/image.pt:8 msgid "Drag&drop an image here to populate the tile." -msgstr "Arraste e solte uma imagem aqui para popular este tile." +msgstr "Arraste e solte uma imagem aqui." + +#: collective/cover/tiles/templates/banner.pt:8 +msgid "Drag&drop an image or link here to populate the tile." +msgstr "Arraste e solte uma imagem ou um link aqui." #: collective/cover/layout_templates/tile.pt:47 msgid "Edit" @@ -180,9 +184,9 @@ msgstr "Filtrar itens" msgid "HTML tag" msgstr "Tag HTML" +#: collective/cover/tiles/banner.py:23 #: collective/cover/tiles/basic.py:36 #: collective/cover/tiles/image.py:18 -#: collective/cover/tiles/link.py:27 msgid "Image" msgstr "Imagem" @@ -262,7 +266,7 @@ msgstr "Arraste e solte um arquivo aqui." #: collective/cover/tiles/templates/link.pt:8 msgid "Please drag&drop a link here to populate the tile." -msgstr "Arraste e solte um link aqui para popular este tile" +msgstr "Arraste e solte um link aquie" #: collective/cover/tiles/templates/basic.pt:9 #: collective/cover/tiles/templates/contentbody.pt:8 @@ -346,12 +350,13 @@ msgstr "Configuração do tile salva." msgid "Tile saved" msgstr "Tile salvo" +#: collective/cover/tiles/banner.py:18 #: collective/cover/tiles/basic.py:26 #: collective/cover/tiles/embed.py:19 -#: collective/cover/tiles/file.py:41 msgid "Title" msgstr "Título" +#: collective/cover/tiles/banner.py:28 #: collective/cover/tiles/link.py:32 msgid "URL" msgstr "URL" diff --git a/src/collective/cover/profiles/default/registry.xml b/src/collective/cover/profiles/default/registry.xml index 40d091761..81336866b 100644 --- a/src/collective/cover/profiles/default/registry.xml +++ b/src/collective/cover/profiles/default/registry.xml @@ -19,14 +19,13 @@ + collective.cover.banner collective.cover.basic collective.cover.carousel collective.cover.collection collective.cover.contentbody collective.cover.embed collective.cover.file - collective.cover.image - collective.cover.link collective.cover.list collective.cover.pfg collective.cover.richtext diff --git a/src/collective/cover/tests/test_banner_tile.py b/src/collective/cover/tests/test_banner_tile.py new file mode 100644 index 000000000..93d3ecec9 --- /dev/null +++ b/src/collective/cover/tests/test_banner_tile.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +from collective.cover.testing import INTEGRATION_TESTING +from collective.cover.tiles.base import IPersistentCoverTile +from collective.cover.tiles.banner import BannerTile +from plone.registry.interfaces import IRegistry +from plone.tiles.interfaces import ITileType +from zope.component import getUtility +from zope.interface.verify import verifyClass +from zope.interface.verify import verifyObject + +import unittest + + +class LinkTileTestCase(unittest.TestCase): + + layer = INTEGRATION_TESTING + + def setUp(self): + self.portal = self.layer['portal'] + self.request = self.layer['request'] + self.name = 'collective.cover.banner' + self.tile = self.portal.restrictedTraverse( + '@@%s/%s' % (self.name, 'test-tile')) + + def test_interface(self): + self.assertTrue(IPersistentCoverTile.implementedBy(BannerTile)) + self.assertTrue(verifyClass(IPersistentCoverTile, BannerTile)) + + tile = BannerTile(None, None) + self.assertTrue(IPersistentCoverTile.providedBy(tile)) + self.assertTrue(verifyObject(IPersistentCoverTile, tile)) + + def test_tile_registration(self): + tile_type = getUtility(ITileType, self.name) + self.assertIsNotNone(tile_type) + self.assertTrue(issubclass(tile_type.schema, IPersistentCoverTile)) + registry = getUtility(IRegistry) + self.assertIn(self.name, registry['plone.app.tiles']) + + def test_default_configuration(self): + self.assertTrue(self.tile.is_configurable) + self.assertTrue(self.tile.is_editable) + self.assertTrue(self.tile.is_droppable) + + def test_accepted_content_types(self): + self.assertListEqual( + self.tile.accepted_ct(), ['Image', 'Link']) + + def test_populate_with_image(self): + obj = self.portal['my-image'] + self.tile.populate_with_object(obj) + self.assertEqual("Test image", self.tile.Title()) + self.assertTrue(self.tile.has_image) + self.assertIsNone(self.tile.getRemoteUrl()) + + def test_populate_with_link(self): + obj = self.portal['my-link'] + self.tile.populate_with_object(obj) + self.assertEqual('Test link', self.tile.data['title']) + self.assertFalse(self.tile.has_image) + # FIXME: set remote_url on the object + self.assertEqual(self.tile.getRemoteUrl(), 'http://') + + def test_render_empty(self): + self.assertIn( + "Drag&drop an image or link here to populate the tile.", self.tile()) + + def test_render_with_image(self): + obj = self.portal['my-image'] + self.tile.populate_with_object(obj) + rendered = self.tile() + self.assertIn('Test link', rendered) diff --git a/src/collective/cover/tiles/banner.py b/src/collective/cover/tiles/banner.py new file mode 100644 index 000000000..84f24ad82 --- /dev/null +++ b/src/collective/cover/tiles/banner.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- + +from Acquisition import aq_base +from collective.cover import _ +from collective.cover.tiles.base import IPersistentCoverTile +from collective.cover.tiles.base import PersistentCoverTile +from plone.namedfile import field +from plone.namedfile import NamedBlobImage +from plone.tiles.interfaces import ITileDataManager +from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile +from zope import schema +from zope.interface import implements + + +class IBannerTile(IPersistentCoverTile): + + title = schema.TextLine( + title=_(u'Title'), + required=False, + ) + + image = field.NamedBlobImage( + title=_(u'Image'), + required=False, + ) + + remote_url = schema.TextLine( + title=_(u'URL'), + required=False, + ) + + +class BannerTile(PersistentCoverTile): + implements(IBannerTile) + + index = ViewPageTemplateFile('templates/banner.pt') + is_configurable = True + is_editable = True + is_droppable = True + + def accepted_ct(self): + return ['Image', 'Link'] + + def populate_with_object(self, obj): + """Tile can be populated with images and links; in this case we're not + going to take care of any modification of the original object; we just + copy the data to the tile and deal with it. + """ + if obj.portal_type not in self.accepted_ct(): + return + + super(BannerTile, self).populate_with_object(obj) # check permissions + obj = aq_base(obj) # avoid acquisition + title = obj.Title() + # if image, store a copy of its data + if obj.portal_type == 'Image': + image = NamedBlobImage(obj.getImage().data) + else: + image = None + remote_url = obj.getRemoteUrl() if obj.portal_type == 'Link' else None + + data_mgr = ITileDataManager(self) + data_mgr.set({ + 'title': title, + 'image': image, + 'remote_url': remote_url, + }) + + def Title(self): + return self.data.get('title', None) + + @property + def has_image(self): + return self.data.get('image', None) is not None + + def getRemoteUrl(self): + return self.data.get('remote_url', None) + + @property + def is_empty(self): + return not (self.Title() or self.has_image or self.getRemoteUrl()) + + # TODO: getting fields configuration is currently a nightmare; we must + # refactor this on the base tile + def get_field_configuration(self, field, attribute=None): + tile_conf = self.get_tile_configuration() + field_conf = tile_conf.get(field, None) + if field_conf: + if attribute is not None: + return field_conf.get(attribute, None) + else: + return field_conf diff --git a/src/collective/cover/tiles/templates/banner.pt b/src/collective/cover/tiles/templates/banner.pt new file mode 100644 index 000000000..9ef34b256 --- /dev/null +++ b/src/collective/cover/tiles/templates/banner.pt @@ -0,0 +1,52 @@ + + + +

+ Drag&drop an image or link here to populate the tile. +

+ + + + diff --git a/src/collective/cover/tiles/tiles.zcml b/src/collective/cover/tiles/tiles.zcml index 1227c7823..41ca250d9 100644 --- a/src/collective/cover/tiles/tiles.zcml +++ b/src/collective/cover/tiles/tiles.zcml @@ -5,6 +5,18 @@ xmlns:plone="http://namespaces.plone.org/plone" i18n_domain="collective.cover"> + +