Re: [Zope] Choice of the sorting key of a dtml-in tag
Yes !!! That's it ! But know, how can I include reverse ;-) ? I've tryed : <a href="<dtml-var URL1>?skey=titre&rev=">Title</a> <a href="<dtml-var URL1>?skey=author&rev=">Author</a> <a href="<dtml-var URL1>?skey=bobobase_modification_time&rev= reverse">Last modification</a> <dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time')"> <dtml-call "REQUEST.set('rev', ' reverse')"> </dtml-if> <dtml-in "objectValues(['article'])" size=3 sort_expr="skey+rev" start=query_start> But it just work with title and author (rev=none) but not with modif_time (rev=' reverse'). Can you help me ?
From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <zope@zope.org> Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag Date: Fri, 13 Jul 2001 07:20:31 -0700
Hi Benoit,
My first answer post!
Although I haven't tried that yet, my understanding is that 'sort' only accepts constants, i.e. it will interpret skey as the literal 'skey', not as its value. You need to use the undocumented 'sort_expr' instead, i.e.
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey" start=query_start>
I'm not sure if you can include 'reverse' in skey; you probably have to state that separately in the dtml-in tag.
Hope that solves your problem,
Do a search on sort_expr on this list for more details.
Cheers,
Jean
On Friday 13 July 2001 15:03, you wrote:
Hi again,
I'd like to make a page with a list of my Zclass instances and to be able to sort them by different key. I tryed with this code :
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time reverse')"> </dtml-if> <dtml-in "objectValues(['article'])" size=3 sort=skey start=query_start>
But it doesn't work : instances are not sorted correctly...
Any idea ?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
I can't think of an easy solution to your problem (you can't just include two versions of the dtml-in tag in a conditional; you would have to have two complete dtml-in loops, one reversed, and one not, and that's a bit ugly), however, it might help to realize that it does you no good to try to pass 'reverse' as a value of some other attribute of dtml-in. 'reverse' is an attribute in itself, and you have to state it explicitely within the tag. How about sorting your articles into another list before the <dtml-in>? I don't have time to try any of this, but you might be able to do something like <dtml-if "rev==''"> <dtml-call "REQUEST.set('sortedArticles', ObjectValues('article').sort(lambda(a,b,k=skey:a[k] < b[k])))"> <dtml-else> <dtml-call "REQUEST.set('sortedArticles', ObjectValues('article').sort(lambda(a,b,k=skey:a[k] > b[k])))"> </dtml-if> <dtml-in sortedArticles ... Caution: I just wrote that code real quick as something that might work. If you like the idea, you'll probably have to fix it somewhat. This may be more easily done in a script. Also, using this way of sorting is probably more inefficient, which matters if you have a lot of articles. Cheers, Jean
-----Original Message----- From: Benoit DOMINIAK [mailto:koubonline@hotmail.com] Sent: Friday, July 13, 2001 07:33 To: jean.lagarde@eer-rc.com Cc: zope@zope.org Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag
Yes !!! That's it ! But know, how can I include reverse ;-) ? I've tryed : <a href="<dtml-var URL1>?skey=titre&rev=">Title</a> <a href="<dtml-var URL1>?skey=author&rev=">Author</a> <a href="<dtml-var URL1>?skey=bobobase_modification_time&rev= reverse">Last modification</a>
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time')"> <dtml-call "REQUEST.set('rev', ' reverse')"> </dtml-if>
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey+rev" start=query_start>
But it just work with title and author (rev=none) but not with modif_time (rev=' reverse').
Can you help me ?
From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <zope@zope.org> Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag Date: Fri, 13 Jul 2001 07:20:31 -0700
Hi Benoit,
My first answer post!
Although I haven't tried that yet, my understanding is that 'sort' only accepts constants, i.e. it will interpret skey as the literal 'skey', not as its value. You need to use the undocumented 'sort_expr' instead, i.e.
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey" start=query_start>
I'm not sure if you can include 'reverse' in skey; you probably have to state that separately in the dtml-in tag. [snip]
When you are working with Zope 2.4 you should have a look at the new 'sequence' module. This one has a sort() function for multi-column sort. This should fit your needs. ========================================================================== Andreas Jung andreas@digicool.com Digital Creations "Zope Dealers" http://www.zope.org ----- Original Message ----- From: "Benoit DOMINIAK" <koubonline@hotmail.com> To: <jean.lagarde@eer-rc.com> Cc: <zope@zope.org> Sent: Freitag, 13. Juli 2001 09:32 Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag
Yes !!! That's it ! But know, how can I include reverse ;-) ? I've tryed : <a href="<dtml-var URL1>?skey=titre&rev=">Title</a> <a href="<dtml-var URL1>?skey=author&rev=">Author</a> <a href="<dtml-var URL1>?skey=bobobase_modification_time&rev= reverse">Last modification</a>
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time')"> <dtml-call "REQUEST.set('rev', ' reverse')"> </dtml-if>
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey+rev" start=query_start>
But it just work with title and author (rev=none) but not with modif_time (rev=' reverse').
Can you help me ?
From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <zope@zope.org> Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag Date: Fri, 13 Jul 2001 07:20:31 -0700
Hi Benoit,
My first answer post!
Although I haven't tried that yet, my understanding is that 'sort' only accepts constants, i.e. it will interpret skey as the literal 'skey', not as its value. You need to use the undocumented 'sort_expr' instead, i.e.
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey" start=query_start>
I'm not sure if you can include 'reverse' in skey; you probably have to state that separately in the dtml-in tag.
Hope that solves your problem,
Do a search on sort_expr on this list for more details.
Cheers,
Jean
On Friday 13 July 2001 15:03, you wrote:
Hi again,
I'd like to make a page with a list of my Zclass instances and to be able to sort them by different key. I tryed with this code :
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time reverse')"> </dtml-if> <dtml-in "objectValues(['article'])" size=3 sort=skey start=query_start>
But it doesn't work : instances are not sorted correctly...
Any idea ?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Benoit, I was looking at the source code (I'm trying to figure out how to put multiple keys in sort_expr -- it does not accept a list as I first assumed), and found that there is also a reverse_expr attribute which will do exactly what you need. So you need to use both sort_expr="skey" and reverse_expr="rev" (I think that rev=='' will not reverse, but if that doesn't work, try setting rev to None). Cheers, Jean
-----Original Message----- From: Benoit DOMINIAK [mailto:koubonline@hotmail.com] Sent: Friday, July 13, 2001 07:33 To: jean.lagarde@eer-rc.com Cc: zope@zope.org Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag
Yes !!! That's it ! But know, how can I include reverse ;-) ? I've tryed : <a href="<dtml-var URL1>?skey=titre&rev=">Title</a> <a href="<dtml-var URL1>?skey=author&rev=">Author</a> <a href="<dtml-var URL1>?skey=bobobase_modification_time&rev= reverse">Last modification</a>
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time')"> <dtml-call "REQUEST.set('rev', ' reverse')"> </dtml-if>
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey+rev" start=query_start>
But it just work with title and author (rev=none) but not with modif_time (rev=' reverse').
Can you help me ?
From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <zope@zope.org> Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag Date: Fri, 13 Jul 2001 07:20:31 -0700
Hi Benoit,
My first answer post!
Although I haven't tried that yet, my understanding is that 'sort' only accepts constants, i.e. it will interpret skey as the literal 'skey', not as its value. You need to use the undocumented 'sort_expr' instead, i.e.
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey" start=query_start>
I'm not sure if you can include 'reverse' in skey; you probably have to state that separately in the dtml-in tag.
Hope that solves your problem,
Do a search on sort_expr on this list for more details.
Cheers,
Jean
On Friday 13 July 2001 15:03, you wrote:
Hi again,
I'd like to make a page with a list of my Zclass instances and to be able to sort them by different key. I tryed with this code :
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time reverse')"> </dtml-if> <dtml-in "objectValues(['article'])" size=3 sort=skey start=query_start>
But it doesn't work : instances are not sorted correctly...
Any idea ?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
The sort attribute only allows one key. To sort by multiple keys you must use _.sequence.sort() (Zope2.4). ========================================================================== Andreas Jung andreas@digicool.com Digital Creations "Zope Dealers" http://www.zope.org ----- Original Message ----- From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <benoit.dominiak@makinacorpus.com> Cc: <zope@zope.org> Sent: Freitag, 13. Juli 2001 16:30 Subject: RE: [Zope] Choice of the sorting key of a dtml-in tag
Benoit,
I was looking at the source code (I'm trying to figure out how to put multiple keys in sort_expr -- it does not accept a list as I first assumed), and found that there is also a reverse_expr attribute which will do exactly what you need.
So you need to use both sort_expr="skey" and reverse_expr="rev" (I think that rev=='' will not reverse, but if that doesn't work, try setting rev to None).
Cheers,
Jean
-----Original Message----- From: Benoit DOMINIAK [mailto:koubonline@hotmail.com] Sent: Friday, July 13, 2001 07:33 To: jean.lagarde@eer-rc.com Cc: zope@zope.org Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag
Yes !!! That's it ! But know, how can I include reverse ;-) ? I've tryed : <a href="<dtml-var URL1>?skey=titre&rev=">Title</a> <a href="<dtml-var URL1>?skey=author&rev=">Author</a> <a href="<dtml-var URL1>?skey=bobobase_modification_time&rev= reverse">Last modification</a>
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time')"> <dtml-call "REQUEST.set('rev', ' reverse')"> </dtml-if>
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey+rev" start=query_start>
But it just work with title and author (rev=none) but not with modif_time (rev=' reverse').
Can you help me ?
From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <zope@zope.org> Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag Date: Fri, 13 Jul 2001 07:20:31 -0700
Hi Benoit,
My first answer post!
Although I haven't tried that yet, my understanding is that 'sort' only accepts constants, i.e. it will interpret skey as the literal 'skey', not as its value. You need to use the undocumented 'sort_expr' instead, i.e.
<dtml-in "objectValues(['article'])" size=3 sort_expr="skey" start=query_start>
I'm not sure if you can include 'reverse' in skey; you probably have to state that separately in the dtml-in tag.
Hope that solves your problem,
Do a search on sort_expr on this list for more details.
Cheers,
Jean
On Friday 13 July 2001 15:03, you wrote:
Hi again,
I'd like to make a page with a list of my Zclass instances and to be able to sort them by different key. I tryed with this code :
<dtml-if "REQUEST.has_key('skey')"> <dtml-else> <dtml-call "REQUEST.set('skey', 'bobobase_modification_time reverse')"> </dtml-if> <dtml-in "objectValues(['article'])" size=3 sort=skey start=query_start>
But it doesn't work : instances are not sorted correctly...
Any idea ?
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Andreas, Hmm, well it seems to work for me! After looking at the code, I tried to pass the dynamic sort keys to sort_expr as a string, e.g. 'sortKey1,sortKey2,sortKey3', and that seems to do the trick. Too scared to make the jump to 2.4 yet. How stable is it? Cheers, Jean
-----Original Message----- From: Andreas Jung [mailto:andreas@andreas-jung.com] Sent: Friday, July 13, 2001 15:38 To: Jean Lagarde; benoit.dominiak@makinacorpus.com Cc: zope@zope.org Subject: Re: [Zope] Choice of the sorting key of a dtml-in tag
The sort attribute only allows one key. To sort by multiple keys you must use _.sequence.sort() (Zope2.4).
========================================================================== Andreas Jung andreas@digicool.com Digital Creations "Zope Dealers" http://www.zope.org
----- Original Message ----- From: "Jean Lagarde" <jean.lagarde@eer-rc.com> To: <benoit.dominiak@makinacorpus.com> Cc: <zope@zope.org> Sent: Freitag, 13. Juli 2001 16:30 Subject: RE: [Zope] Choice of the sorting key of a dtml-in tag
Benoit,
I was looking at the source code (I'm trying to figure out how to put multiple keys in sort_expr -- it does not accept a list as I first assumed), and found that there is also a reverse_expr attribute which will do exactly what you need.
So you need to use both sort_expr="skey" and reverse_expr="rev" (I think that rev=='' will not reverse, but if that doesn't work, try setting rev to None).
Cheers,
Jean
[snip]
Too scared to make the jump to 2.4 yet. How stable is it?
We have 2.4b3 and 2.4.0 will be released soon. We've made lots and lots of fixes and may introduced some new bugs :-) So it is up to you to decide when to upgrade. Andreas
participants (3)
-
Andreas Jung -
Benoit DOMINIAK -
Jean Lagarde