Skip to content

Commit

Permalink
Merge 8e68d63 into 6f9482a
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonc committed Aug 10, 2018
2 parents 6f9482a + 8e68d63 commit 5ab9823
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
exclude_paths:
- bootstrap.py
- setup.py
- webpack/app/vendor/swiper.min.css
- webpack/app/vendor/swiper.min.js
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

2.0a1 (unreleased)
^^^^^^^^^^^^^^^^^^
- Adiciona um tile para mostrar uma Galeria de fotos.
[claytonc]

- Adiciona um tile para mostrar a Foto do Dia.
[claytonc, hvelarde]
Expand Down
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Mostra uma citação de uma matéria.
:height: 250px
:width: 530px

Foto do Día
Foto do Dia
^^^^^^^^^^^
Mostra uma foto excepcional selecionada diariamente.

Expand All @@ -102,6 +102,15 @@ Mostra uma foto excepcional selecionada diariamente.
:height: 577px
:width: 867px

Galeria de fotos
^^^^^^^^^^^^^^^^
Mostra uma galeria de fotos.

.. figure:: https://raw.github.com/plonegovbr/brasil.gov.tiles/master/docs/photogallery.png
:align: center
:height: 533px
:width: 800px

Desenvolvimento
---------------

Expand Down
Binary file added docs/photogallery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/brasil/gov/tiles/profiles/default/cssregistry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<stylesheet title="" cacheable="True" compression="safe" cookable="True"
enabled="1" expression="" id="++resource++brasil.gov.tiles/brasilgovtiles.css" media="screen"
rel="stylesheet" rendering="link" insert-after="*" />
<stylesheet title="" cacheable="True" compression="safe" cookable="True"
enabled="1" expression="" id="++resource++brasil.gov.tiles/vendor/swiper.min.css" media="screen"
rel="stylesheet" rendering="link" insert-after="*" />
</object>
3 changes: 3 additions & 0 deletions src/brasil/gov/tiles/profiles/default/jsregistry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<javascript id="++resource++brasil.gov.tiles/vendor/jquery.cycle2.carousel.js"
cacheable="True" compression="none" cookable="True" enabled="True"
expression="" inline="False" authenticated="False" insert-after="++resource++brasil.gov.tiles/vendor/jquery.cycle2.js" />
<javascript id="++resource++brasil.gov.tiles/vendor/swiper.min.js"
cacheable="True" compression="none" cookable="True" enabled="True"
expression="" inline="False" authenticated="False" insert-after="++resource++brasil.gov.tiles/vendor/jquery.cycle2.carousel.js" />
</object>
1 change: 1 addition & 0 deletions src/brasil/gov/tiles/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<element>albuns</element>
<element>brasil.gov.tiles.potd</element>
<element>brasil.gov.tiles.quote</element>
<element>brasil.gov.tiles.photogallery</element>
</value>
</record>
</registry>
85 changes: 85 additions & 0 deletions src/brasil/gov/tiles/tests/test_photogallery_tile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- coding: utf-8 -*-
from brasil.gov.tiles.testing import BaseIntegrationTestCase
from brasil.gov.tiles.tiles.photogallery import PhotoGalleryTile
from collective.cover.tiles.base import IPersistentCoverTile
from mock import Mock
from plone.tiles.interfaces import ITileDataManager
from zope.interface.verify import verifyClass
from zope.interface.verify import verifyObject


class PhotoGalleryTileTestCase(BaseIntegrationTestCase):

def setUp(self):
super(PhotoGalleryTileTestCase, self).setUp()
self.tile = self.portal.restrictedTraverse(
'@@{0}/{1}'.format('brasil.gov.tiles.photogallery', 'test-tile'))

def test_interface(self):
self.assertTrue(IPersistentCoverTile.implementedBy(PhotoGalleryTile))
self.assertTrue(verifyClass(IPersistentCoverTile, PhotoGalleryTile))

tile = PhotoGalleryTile(None, None)
self.assertTrue(IPersistentCoverTile.providedBy(tile))
self.assertTrue(verifyObject(IPersistentCoverTile, tile))

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'])

def test_tile_is_empty(self):
self.assertTrue(self.tile.is_empty())

def test_render_empty(self):
msg = 'Drag&amp;drop an image here to populate the tile.'

self.tile.is_compose_mode = Mock(return_value=True)
self.assertIn(msg, self.tile())

self.tile.is_compose_mode = Mock(return_value=False)
self.assertNotIn(msg, self.tile())

def test_crud(self):
self.assertTrue(self.tile.is_empty())

obj = self.portal['my-image']
obj2 = self.portal['my-image1']
obj3 = self.portal['my-image2']

self.tile.populate_with_object(obj)
self.tile.populate_with_object(obj2)
self.tile.populate_with_object(obj3)

self.tile = self.portal.restrictedTraverse(
'@@{0}/{1}'.format('brasil.gov.tiles.photogallery', 'test-tile'))

self.assertEqual(len(self.tile.results()), 3)
self.assertIn(obj, self.tile.results())
self.assertIn(obj2, self.tile.results())
self.assertIn(obj3, self.tile.results())

data = self.tile.data
data['tile_title'] = 'My title'
data_mgr = ITileDataManager(self.tile)
data_mgr.set(data)

self.tile = self.portal.restrictedTraverse(
'@@{0}/{1}'.format('brasil.gov.tiles.photogallery', 'test-tile'))
self.assertEqual(self.tile.tile_title, 'My title')

def test_render_with_image(self):
obj = self.portal['my-image']
self.tile.populate_with_object(obj)
rendered = self.tile()
self.assertFalse(self.tile.is_empty())
self.assertIn('<img ', rendered)
self.assertIn('alt="This image was created for testing purposes"', rendered)

def test_thumbnail(self):
obj = self.portal['my-image']
thumbnail = self.tile.thumbnail(obj)
self.assertIsNotNone(thumbnail)
26 changes: 24 additions & 2 deletions src/brasil/gov/tiles/tests/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_profile_version(self):

def test_registered_steps(self):
steps = len(self.setup.listUpgrades(self.profile_id)[0])
self.assertEqual(steps, 5)
self.assertEqual(steps, 6)

def test_update_resources_references(self):
# address also an issue with Setup permission
Expand All @@ -63,34 +63,42 @@ def test_update_resources_references(self):

css_ids = css_tool.getResourceIds()
self.assertIn('++resource++brasil.gov.tiles/tiles.css', css_ids)
self.assertIn('++resource++brasil.gov.tiles/swiper.min.css', css_ids)
self.assertNotIn('++resource++brasil.gov.tiles/brasilgovtiles.css', css_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/swiper.min.css', css_ids)

js_ids = js_tool.getResourceIds()
self.assertIn('++resource++brasil.gov.tiles/tiles.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/jquery.cycle2.carousel.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/jquery.cycle2.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/jquery.jplayer.min.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/brasilgovtiles.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/swiper.min.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/brasilgovtiles.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/jquery.cycle2.carousel.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/jquery.cycle2.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/jquery.jplayer.min.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/vendor/swiper.min.js', js_ids)

# run the upgrade step to validate the update
self._do_upgrade(step)

css_ids = css_tool.getResourceIds()
self.assertIn('++resource++brasil.gov.tiles/brasilgovtiles.css', css_ids)
self.assertIn('++resource++brasil.gov.tiles/vendor/swiper.min.css', css_ids)
self.assertNotIn('++resource++brasil.gov.tiles/tiles.css', css_ids)
self.assertNotIn('++resource++brasil.gov.tiles/swiper.min.css', css_ids)

js_ids = js_tool.getResourceIds()
self.assertIn('++resource++brasil.gov.tiles/brasilgovtiles.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/vendor/jquery.cycle2.carousel.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/vendor/jquery.cycle2.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/vendor/jquery.jplayer.min.js', js_ids)
self.assertIn('++resource++brasil.gov.tiles/vendor/swiper.min.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/tiles.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/jquery.cycle2.carousel.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/jquery.cycle2.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/jquery.jplayer.min.js', js_ids)
self.assertNotIn('++resource++brasil.gov.tiles/swiper.min.js', js_ids)

@staticmethod
def get_registered_tiles():
Expand Down Expand Up @@ -139,3 +147,17 @@ def test_add_quote_tile(self):

self.assertIn(tile, self.get_registered_tiles())
self.assertIn(tile, self.get_available_tiles())

def test_add_photogallery_tile(self):
title = u'Add Photo Gallery tile'
step = self._get_upgrade_step_by_title(title)
self.assertIsNotNone(step)

tile = u'brasil.gov.tiles.photogallery'
self.unregister_tile(tile)

# run the upgrade step to validate the update
self._do_upgrade(step)

self.assertIn(tile, self.get_registered_tiles())
self.assertIn(tile, self.get_available_tiles())
13 changes: 13 additions & 0 deletions src/brasil/gov/tiles/tiles/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,17 @@
permission="zope.Public"
/>

<plone:tile
name="brasil.gov.tiles.photogallery"
title="Photo Gallery"
description="Display a photo of the day section."
add_permission="cmf.ModifyPortalContent"
schema=".photogallery.IPhotoGalleryTile"
icon="++resource++collective.cover/img/tile-banner.png"
class=".photogallery.PhotoGalleryTile"
permission="zope2.View"
for="*"
i18n:attributes="title; description"
/>

</configure>
62 changes: 62 additions & 0 deletions src/brasil/gov/tiles/tiles/photogallery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
from brasil.gov.tiles import _
from collective.cover.interfaces import ITileEditForm
from collective.cover.tiles.list import IListTile
from collective.cover.tiles.list import ListTile
from collective.cover.widgets.textlinessortable import TextLinesSortableFieldWidget
from plone.autoform import directives as form
from plone.tiles.interfaces import ITileDataManager
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from zope import schema
from zope.interface import implementer


class IPhotoGalleryTile(IListTile):
"""A tile that shows an photo gallery."""

tile_description = schema.Text(title=_(u'Tile Description'), required=False)
form.omitted('tile_description')
form.no_omit(ITileEditForm, 'tile_description')

form.no_omit(ITileEditForm, 'uuids')
form.widget(uuids=TextLinesSortableFieldWidget)


@implementer(IPhotoGalleryTile)
class PhotoGalleryTile(ListTile):
"""A tile that shows an photo gallery."""

index = ViewPageTemplateFile('templates/photogallery.pt')
short_name = _(u'msg_short_photo_gallery', default=u'Photo Gallery')
is_configurable = True
is_droppable = True
is_editable = True
limit = 5 * 3

@staticmethod
def accepted_ct():
return ['Image']

def get_description(self, item):
"""Get the description of the item, or the custom description
if set.
:param item: [required] The item for which we want the description
:type item: Content object
:returns: the item description
:rtype: unicode
"""
# First we get the url for the item itself
description = item.Description()
uuid = self.get_uuid(item)
data_mgr = ITileDataManager(self)
data = data_mgr.get()
uuids = data['uuids']
if uuid in uuids:
if uuids[uuid].get('custom_description', u''):
# If we had a custom description set, then get that
description = uuids[uuid].get('custom_description')
return description

@staticmethod
def get_credits(item):
return item.Rights()
50 changes: 50 additions & 0 deletions src/brasil/gov/tiles/tiles/templates/photogallery.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="brasil.gov.tiles">
<body tal:define="is_empty view/is_empty">

<p tal:condition="python: is_empty and view.is_compose_mode()" i18n:translate="">
Drag&amp;drop an image here to populate the tile.
</p>

<div class="brasil-photogallery-tile tile-content"
tal:attributes="id string:gallery-${view/id}"
tal:condition="not:is_empty">
<h3 class="gallery-title" tal:content="view/tile_title" />
<div class="swiper-container photogallery-container">
<div class="swiper-wrapper">
<tal:items repeat="item view/results">
<div class="swiper-slide"
tal:attributes="data-tile-id view/id;
data-content-type item/portal_type;
data-content-uuid python:view.get_uuid(item)">
<div class="image-container">
<tal:image tal:define="thumbnail python:view.thumbnail(item);"
tal:condition="thumbnail">
<img tal:attributes="src thumbnail/url;
class string:gallery-image;
alt python:view.get_alt(item);" />
<div class="container-bar">
<div class="text-bottom">
<p class="description" tal:content="python:view.get_description(item)">Description</p>
<p class="credits" tal:content="python:view.get_credits(item)">Credits</p>
</div>

<div class="links-bottom">
<a tal:attributes="href string:${item/absolute_url}/@@download/image" class="download-icon">Download</a>
<a tal:attributes="href string:${item/absolute_url}/@@images/image" class="zoom-icon">Zoom</a>
</div>
</div>
</tal:image>
</div>
</div>
</tal:items>
</div>
<div class="swiper-button-next swiper-button-white"></div>
<div class="swiper-button-prev swiper-button-white"></div>
</div>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions src/brasil/gov/tiles/upgrades/v4100/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

RESOURCES_TO_UPDATE = {
'++resource++brasil.gov.tiles/tiles.css': '++resource++brasil.gov.tiles/brasilgovtiles.css',
'++resource++brasil.gov.tiles/swiper.min.css': '++resource++brasil.gov.tiles/vendor/swiper.min.css',
'++resource++brasil.gov.tiles/tiles.js': '++resource++brasil.gov.tiles/brasilgovtiles.js',
'++resource++brasil.gov.tiles/jquery.cycle2.carousel.js': '++resource++brasil.gov.tiles/vendor/jquery.cycle2.carousel.js',
'++resource++brasil.gov.tiles/jquery.cycle2.js': '++resource++brasil.gov.tiles/vendor/jquery.cycle2.js',
'++resource++brasil.gov.tiles/jquery.jplayer.min.js': '++resource++brasil.gov.tiles/vendor/jquery.jplayer.min.js',
'++resource++brasil.gov.tiles/swiper.min.js': '++resource++brasil.gov.tiles/vendor/swiper.min.js',
}


Expand Down Expand Up @@ -38,3 +40,8 @@ def add_quote_tile(setup_tool):
def add_potd_tile(setup_tool):
"""Add Photo of the Day tile."""
add_tile(u'brasil.gov.tiles.potd')


def add_photogallery_tile(setup_tool):
"""Add Photo Gallery tile."""
add_tile(u'brasil.gov.tiles.photogallery')
5 changes: 5 additions & 0 deletions src/brasil/gov/tiles/upgrades/v4100/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
handler=".add_quote_tile"
/>

<genericsetup:upgradeStep
title="Add Photo Gallery tile"
handler=".add_photogallery_tile"
/>

<genericsetup:upgradeStep
title="Cook CSS resources"
description="There were changes in the CSS files, so we need to cook the resources."
Expand Down

0 comments on commit 5ab9823

Please sign in to comment.