Sort a list with ZPT
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. 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 this doesn't work. What am I doing wrong? Greetz Nico
Nico de Boer wrote:
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.
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 this doesn't work. What am I doing wrong?
maybe <div tal:define="itemlist python:here.list_peers(id='date_add')"> ? -- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
hans wrote:
Nico de Boer wrote:
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.
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 this doesn't work. What am I doing wrong?
maybe <div tal:define="itemlist python:here.list_peers(id='date_add')"> ?
ähem, typo <div tal:define="itemlist python:here.list_peers(sortkey='date_add')"> -- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
participants (2)
-
hans -
Nico de Boer