jjkingの日記: Ploneの「最近公開されたアイテム」のカスタマイズをする
日記 by
jjking
Plone2 の「最近公開のアイテム」はログインしているユーザーにのみ表示され、かつ表示されるアイテムも、最終ログインの時からの差分となっている。これを最近更新されたページ一覧を表示するための部品として使えるように改造を行った。
この部品の名称は portlet_recent で、ZMI (Zope の管理画面)からは /plone/portal_skins/plone_portlets/portlet_recent というパスで参照できる。
まず、「最近公開のアイテム」ポートレットの改造(http://www.liris.org/technology/plone/plone_custumize02)のページを参考にして、ログオンしていないユーザーでも表示されて、なおかつ最近更新されたもののみを表示するようにした。
ただ、このままだと表示される日付がドキュメントの作成日付であって、最終更新日ではない。そのため、さらにコード中の以下の行の obj.Date の部分を obj.modified に変更する。
<div class="portletDetails"
tal:content="python:here.toPortalTime(obj.Date)">July 7, 08:11</div>
portlet_recent は最終的には以下のようなコードとなった。ラベルが「最近公開されたアイテム」のままで少し変だが、ここは大目に見よう。
--- ここから ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
i18n:domain="plone">
<body>
<!-- The Recent Items box -->
<div metal:define-macro="portlet">
<tal:recentlist tal:define="last_time python:DateTime()-14;
results python:request.get('items',
here.portal_catalog.searchResults(
modified={'query': last_time,'range': 'min'},
sort_on='modified',
sort_order='reverse', review_state='published')[:5]);">
<div class="portlet" id="portlet-recent">
<h5 i18n:translate="box_recentitems">Recent Items</h5>
<div class="portletBody">
<tal:block tal:repeat="obj results">
<div tal:define="oddrow repeat/obj/odd"
tal:attributes="class python:test(oddrow, 'portletContent even', 'portletContent odd')">
<a href=""
tal:attributes="href string:${obj/getURL}/view;
title obj/Description">
<span tal:replace="python:test(obj.Title, obj.Title, obj.id)"> Item title </span>
</a>
<div class="portletDetails"
tal:content="python:here.toPortalTime(obj.modified)">July 7, 08:11</div>
</div>
</tal:block>
<div class="portletContent odd" tal:condition="not: results"
i18n:translate="box_recently_no_items">
No items published or changed since your last log-in.
</div>
<div class="portletContent odd">
<a href=""
class="portletMore"
tal:attributes="href string:${portal_url}/recently_published"
i18n:translate="box_morelink"
>
More...
</a>
</div>
</div>
</div>
</tal:recentlist>
</div>
</body>
</html>
--- ここまで ---
この部品の名称は portlet_recent で、ZMI (Zope の管理画面)からは /plone/portal_skins/plone_portlets/portlet_recent というパスで参照できる。
まず、「最近公開のアイテム」ポートレットの改造(http://www.liris.org/technology/plone/plone_custumize02)のページを参考にして、ログオンしていないユーザーでも表示されて、なおかつ最近更新されたもののみを表示するようにした。
ただ、このままだと表示される日付がドキュメントの作成日付であって、最終更新日ではない。そのため、さらにコード中の以下の行の obj.Date の部分を obj.modified に変更する。
<div class="portletDetails"
tal:content="python:here.toPortalTime(obj.Date)">July 7, 08:11</div>
portlet_recent は最終的には以下のようなコードとなった。ラベルが「最近公開されたアイテム」のままで少し変だが、ここは大目に見よう。
--- ここから ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
i18n:domain="plone">
<body>
<!-- The Recent Items box -->
<div metal:define-macro="portlet">
<tal:recentlist tal:define="last_time python:DateTime()-14;
results python:request.get('items',
here.portal_catalog.searchResults(
modified={'query': last_time,'range': 'min'},
sort_on='modified',
sort_order='reverse', review_state='published')[:5]);">
<div class="portlet" id="portlet-recent">
<h5 i18n:translate="box_recentitems">Recent Items</h5>
<div class="portletBody">
<tal:block tal:repeat="obj results">
<div tal:define="oddrow repeat/obj/odd"
tal:attributes="class python:test(oddrow, 'portletContent even', 'portletContent odd')">
<a href=""
tal:attributes="href string:${obj/getURL}/view;
title obj/Description">
<span tal:replace="python:test(obj.Title, obj.Title, obj.id)"> Item title </span>
</a>
<div class="portletDetails"
tal:content="python:here.toPortalTime(obj.modified)">July 7, 08:11</div>
</div>
</tal:block>
<div class="portletContent odd" tal:condition="not: results"
i18n:translate="box_recently_no_items">
No items published or changed since your last log-in.
</div>
<div class="portletContent odd">
<a href=""
class="portletMore"
tal:attributes="href string:${portal_url}/recently_published"
i18n:translate="box_morelink"
>
More...
</a>
</div>
</div>
</div>
</tal:recentlist>
</div>
</body>
</html>
--- ここまで ---
Ploneの「最近公開されたアイテム」のカスタマイズをする More ログイン