[Zope] sort list with ZPT

Nico de Boer nico@nfg.nl
03 Jun 2002 16:25:43 +0200


Hi all,

I want to sort my objectValues('News') at date_add, the date that the
News objects were added.

I have written a python method to do this:

    def list_peers(self, sortkey='id'):
        """returns a listing of peer news objects sorted on sortkey"""
        itemlist = []
        for item in self.REQUEST['PARENTS'][1].objectValues('GNAW'):
            itemlist.append(
                (getattr(item,sortkey),item)
                )
        itemlist.sort()
        return itemlist

I can give the sortkey as an argument to the method.

When I put the following lines:

<div tal:define="itemlist python:here.list_peers(sortkey='date_add')">
<span tal:repeat="item itemlist"><p tal:content="item"></p></span>

in my ZPT I get the following output:

(<News instance at 92c0e48>, '29 may 2002')

(<News instance at 92c0f10>, '30 may 2002')

(<News instance at 92c0418>, '31 may 2002')

Now I want to implement this in ZPT as follows:

<div tal:define="itemlist python:here.list_peers">  
<div tal:repeat="item itemlist">
    <a href="#"
    tal:attributes="href item/absolute_url"
    tal:content="item/title">Title news</a> </div>
</div>

But I get Undefined Errors. How can I get to the items in the itemlist?

Greetz Nico