Skip to content

Commit

Permalink
Merge pull request #334 from warpr/issue_298
Browse files Browse the repository at this point in the history
 Issue #298, Add offset as a configuration option to the collection tile.
  • Loading branch information
hvelarde committed Oct 29, 2013
2 parents c9328d8 + c6c114b commit 0981e42
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 13 deletions.
7 changes: 5 additions & 2 deletions CHANGES.rst
Expand Up @@ -4,9 +4,11 @@ There's a frood who really knows where his towel is
1.0a6 (unreleased)
^^^^^^^^^^^^^^^^^^

- Add offset as a configuration option to the collection tile.
(fixes `#298`_). [warpr]

- Add ``cover-(type)-tile`` class to all tile templates (fixes issue
`#189`_).
[warpr]
`#189`_). [warpr]

- Support text from Dexterity items for the bodycontent and richtext
tiles (fixes `#323`_). [maurits]
Expand Down Expand Up @@ -303,6 +305,7 @@ There's a frood who really knows where his towel is
.. _`#281`: https://github.com/collective/collective.cover/issues/281
.. _`#294`: https://github.com/collective/collective.cover/issues/294
.. _`#295`: https://github.com/collective/collective.cover/issues/295
.. _`#298`: https://github.com/collective/collective.cover/issues/298
.. _`#301`: https://github.com/collective/collective.cover/issues/301
.. _`#303`: https://github.com/collective/collective.cover/issues/303
.. _`#314`: https://github.com/collective/collective.cover/issues/314
Expand Down
53 changes: 53 additions & 0 deletions src/collective/cover/tests/test_collection_tile.py
Expand Up @@ -126,3 +126,56 @@ def test_thumbnail(self):
self.assertFalse(self.tile.thumbnail(obj))

# TODO: test against Dexterity-based content types

def test_number_of_items(self):
collection = self.portal['my-collection']
image_query = [{
'i': 'Type',
'o': 'plone.app.querystring.operation.string.is',
'v': 'Image',
}]
collection.setQuery(image_query)
collection.setSort_on('id')
self.tile.populate_with_object(collection)

# Collection has three images and shows them all.
self.assertEqual(len(self.tile.results()), 3)

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

# Collection has three images and shows the first two items.
items = self.tile.results()
self.assertEqual(len(items), 2)
self.assertEqual(items[0].getId(), 'my-image')
self.assertEqual(items[1].getId(), 'my-image1')

def test_offset(self):
collection = self.portal['my-collection']
image_query = [{
'i': 'Type',
'o': 'plone.app.querystring.operation.string.is',
'v': 'Image',
}]
collection.setQuery(image_query)
collection.setSort_on('id')
self.tile.populate_with_object(collection)

tile_conf = self.tile.get_tile_configuration()
tile_conf['offset']['offset'] = 1
self.tile.set_tile_configuration(tile_conf)

# Collection has three images and shows the final two.
items = self.tile.results()
self.assertEqual(len(items), 2)
self.assertEqual(items[0].getId(), 'my-image1')
self.assertEqual(items[1].getId(), 'my-image2')

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

items = self.tile.results()
self.assertEqual(len(items), 1)
self.assertEqual(items[0].getId(), 'my-image1')
17 changes: 16 additions & 1 deletion src/collective/cover/tiles/collection.py
Expand Up @@ -61,6 +61,13 @@ class ICollectionTile(IPersistentCoverTile, form.Schema):
required=False,
)

form.omitted('offset')
form.no_omit(IDefaultConfigureForm, 'offset')
offset = schema.Int(
title=_(u'Start at item'),
required=False,
)

footer = schema.TextLine(
title=_(u'Footer'),
required=False,
Expand Down Expand Up @@ -92,10 +99,15 @@ def results(self):
else:
size = 4

offset = 0
offset_conf = [i for i in self.configured_fields if i['id'] == 'offset']
if offset_conf:
offset = int(offset_conf[0].get('offset', 0))

uuid = self.data.get('uuid', None)
obj = uuidToObject(uuid)
if uuid and obj:
return obj.results(batch=False)[:size]
return obj.results(batch=False)[offset:offset + size]
else:
self.remove_relation()
return []
Expand Down Expand Up @@ -154,6 +166,9 @@ def get_configured_fields(self):
if 'size' in field_conf:
field['size'] = field_conf['size']

if 'offset' in field_conf:
field['offset'] = field_conf['offset']

results.append(field)

return results
Expand Down
34 changes: 24 additions & 10 deletions src/collective/cover/tiles/configuration_widgets/textline.pt
Expand Up @@ -47,21 +47,35 @@
accesskey view/accesskey|nothing;"/>
</div>

<span i18n:translate="">HTML tag</span>
<select id="" name="" class=""
tabindex="" accesskey=""
tal:attributes="id string:${view/id}-htmltag;
name string:${view/name}.htmltag;
class view/klass;
tabindex view/tabindex;
accesskey view/accesskey|nothing;"
tal:define="values python:['h1', 'h2', 'h3', 'h4']">
<tal:if condition="python: isinstance (view.field, modules['zope.schema'].Int)">
<span i18n:translate="">Position</span>
<input type="text" id="" name="" class="" size="2"
tabindex="" accesskey=""
tal:attributes="id string:${view/id}-offset;
name string:${view/name}.offset;
class view/klass;
tabindex view/tabindex;
value python:stored_data.get('offset', None);
accesskey view/accesskey|nothing;"/>
</tal:if>

<tal:if condition="python: isinstance (view.field, modules['zope.schema'].TextLine)">
<span i18n:translate="">HTML tag</span>
<select id="" name="" class=""
tabindex="" accesskey=""
tal:attributes="id string:${view/id}-htmltag;
name string:${view/name}.htmltag;
class view/klass;
tabindex view/tabindex;
accesskey view/accesskey|nothing;"
tal:define="values python:['h1', 'h2', 'h3', 'h4']">

<option tal:repeat="value values"
tal:attributes="value value;
selected python:stored_data.get('htmltag', None) == value and 'selected' or None"
tal:content="python:value.upper()">HTML TAG</option>
</select>
</select>
</tal:if>

</tal:stored_data>
</html>

0 comments on commit 0981e42

Please sign in to comment.