Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Issue collective#298, Add offset as a configuration option to the col…
Browse files Browse the repository at this point in the history
…lection tile.

This adds a configuration option "Start at item".  With this option two or more collection tiles
can be used to show different slices of the same collection.
  • Loading branch information
warpr committed Oct 29, 2013
1 parent b069a4a commit 8ff071b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
17 changes: 16 additions & 1 deletion src/collective/cover/tiles/collection.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8ff071b

Please sign in to comment.