2001/12/04 cheeseshop
DTMLではdtml-inでソートできるが、PythonScriptやPageTemplateではどうするか?
Zope2.4.0からsequenceモジュールが追加され、これを使えば特定の属性でソートをかけることができる。例えばオブジェクトを更新日時で逆順にソートする場合だとこんな感じ。:
for item in sequence.sort(
container.objectValues(),
(('bobobase_modification_time','cmp','desc'),) ):
print item.title_or_id(),'-',
item.bobobase_modification_time(),'<br>'
return printed
PageTemplateならこんな感じになる (おまけでアイコンも表示させてみた :-) :
<table>
<tr tal:repeat="item python:sequence.sort(
container.objectValues(),
(('bobobase_modification_time','cmp','desc'),))">
<td><img tal:attributes="src item/icon" /></td>
<td tal:content="item/title_or_id"></td>
<td tal:content="item/bobobase_modification_time"></td>
</tr>
</table>
コメント
| Last edited Sat, 09 Sep 2006 19:30:55 +0900 | Edit this page |