-
Notifications
You must be signed in to change notification settings - Fork 54
Solves Issue #447 #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Solves Issue #447 #802
Changes from all commits
1f9f8f7
e8a4555
7417fd7
eb2ca16
a39e629
c9b8646
c949540
4bdae9d
0fb2baa
bcc9fa5
39181f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why change the schema here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as in collection https://github.com/collective/collective.cover/pull/802/files/39181f51604a56eae22ccf300c386012ad810081#r210260938 |
||
| title=_(u'Number of items to display'), | ||
| value_type=schema.TextLine(), | ||
| required=False, | ||
| default=5, | ||
| ) | ||
|
|
||
| form.omitted('title') | ||
|
|
@@ -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(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| 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(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.