Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/collective/cover/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>21</version>
<version>22</version>
<dependencies>
<dependency>profile-collective.js.galleria:default</dependency>
<dependency>profile-collective.js.jqueryui:default</dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/collective/cover/tests/test_collection_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_number_of_items(self):
self.assertEqual(len(self.tile.results()), 3)

tile_conf = self.tile.get_tile_configuration()
tile_conf['number_to_show']['size'] = 2
tile_conf['count']['size'] = 2
self.tile.set_tile_configuration(tile_conf)

# Collection has three images and shows the first two items.
Expand All @@ -166,7 +166,7 @@ def test_offset(self):
self.assertEqual(items[1].getId(), 'my-image2')

# Add a size, so only one item is left.
tile_conf['number_to_show']['size'] = 1
tile_conf['count']['size'] = 1
self.tile.set_tile_configuration(tile_conf)

items = self.tile.results()
Expand Down
9 changes: 4 additions & 5 deletions src/collective/cover/tiles/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ class ICollectionTile(IPersistentCoverTile):
required=False,
)

# FIXME: this field should be named 'count'
form.omitted('number_to_show')
form.no_omit(IDefaultConfigureForm, 'number_to_show')
number_to_show = schema.List(
form.omitted('count')
form.no_omit(IDefaultConfigureForm, 'count')
count = schema.List(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema says List, but you are working like if it was a dictionary.. could you please explain the idea behind this schema change? Why a simple Int don't resolve this problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only just kept the model already existing schema in the collection tile, but yes, a simple Int resolve this problem.

title=_(u'Number of items to display'),
value_type=schema.TextLine(),
required=False,
Expand Down Expand Up @@ -106,7 +105,7 @@ def get_title(self):

def results(self):
self.configured_fields = self.get_configured_fields()
size_conf = [i for i in self.configured_fields if i['id'] == 'number_to_show']
size_conf = [i for i in self.configured_fields if i['id'] == 'count']

if size_conf and 'size' in size_conf[0].keys():
size = int(size_conf[0]['size'])
Expand Down
14 changes: 7 additions & 7 deletions src/collective/cover/tiles/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ class IListTile(IPersistentCoverTile):
)
form.omitted('uuids')

# XXX: this field should be used to replace the 'limit' attribute
form.omitted('count')
form.no_omit(IDefaultConfigureForm, 'count')
count = schema.Int(
count = schema.List(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the schema here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title=_(u'Number of items to display'),
value_type=schema.TextLine(),
required=False,
default=5,
)

form.omitted('title')
Expand Down Expand Up @@ -153,11 +152,12 @@ def Date(self, obj):
assert len(brain) == 1
return super(ListTile, self).Date(brain[0])

# TODO: get rid of this by replacing it with the 'count' field
def set_limit(self):
for field in self.get_configured_fields():
if field and field.get('id') == 'uuids':
self.limit = int(field.get('size', self.limit))
self.config_fields = self.get_tile_configuration()
limit_conf = self.config_fields.get('count', None)

if limit_conf and 'size' in limit_conf.keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit_conf = self.config_fields.get('count', [])
if 'size' in limit_conf:
   ...

self.limit = int(limit_conf.get('size', self.limit))

def populate_with_object(self, obj):
""" Add an object to the list of items
Expand Down
1 change: 1 addition & 0 deletions src/collective/cover/upgrades/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<include package=".v19" />
<include package=".v20" />
<include package=".v21" />
<include package=".v22" />
</configure>
49 changes: 49 additions & 0 deletions src/collective/cover/upgrades/v22/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from collective.cover.logger import logger
from plone.tiles.interfaces import ITileType
from zope.component import getUtility
from zope.dottedname.resolve import resolve
from zope.schema.interfaces import IVocabularyFactory


def fix_fields(context):
"""tiles here"""

# Get covers
covers = context.portal_catalog(portal_type='collective.cover.content')
iface = 'collective.cover.tiles.collection.ICollectionTile'
logger.info('About to update {0} objects'.format(len(covers)))
tiles_to_update = _get_tiles_inherit_from_interface(context, iface=iface)
logger.info('{0} tile types will be updated ({1})'.format(
len(tiles_to_update), ', '.join(tiles_to_update)))
for cover in covers:
obj = cover.getObject()
tile_ids = obj.list_tiles(types=tiles_to_update)
for tile_id in tile_ids:
tile = obj.get_tile(tile_id)
tile_conf = tile.get_tile_configuration()

if 'number_to_show' in tile_conf.keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep short indentation

if 'number_to_show' not in tile_conf:
    continue

tile_conf['count'] = tile_conf['number_to_show']
tile_conf.pop('number_to_show')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tile_conf['count'] = tile_conf.pop('number_to_show')

tile.set_tile_configuration(tile_conf)

msg = 'Tile {0} at {1} updated'
logger.info(msg.format(tile_id, cover.getPath()))

logger.info('Done')


def _get_tiles_inherit_from_interface(context, iface=None):
"""Returns a list of all tiles inherited from a given interface."""
name = 'collective.cover.EnabledTiles'
tiles_to_update = []
if iface:
Iface = resolve(iface)
enabled_tiles = getUtility(IVocabularyFactory, name)(context)
tiles_to_update = []
for i in enabled_tiles:
tile = getUtility(ITileType, i.value)
if issubclass(tile.schema, Iface):
tiles_to_update.append(i.value)
return tiles_to_update
20 changes: 20 additions & 0 deletions src/collective/cover/upgrades/v22/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="collective.cover">

<genericsetup:upgradeSteps
source="21"
destination="22"
profile="collective.cover:default">

<genericsetup:upgradeStep
title="Revert the collection field of number_to_show to count"
description=""
handler=".fix_fields"
/>

</genericsetup:upgradeSteps>

</configure>