[Zope] Newbie Question: Ordering items within a folder based on a property

Casey Duncan casey@zope.com
Thu, 28 Mar 2002 12:50:13 -0700


Ahh, bitten by acquisition.

But, I think we can actually use acquistion here to defeat itself. Put a 
python script named "getSortValue" wherever this dtml method is. Put the 
following in it:

     return context.getProperty('sort_value', 0)

Then change your sort attribute of your dtml-in to: 
sort="getSortValue,title_or_id"

The trick here is that getProperty doesn't acquire values. The second 
argument is the default if the property is not defined on the object. 
You should set this lower than the lowest possible sort_value.

hth,

-Casey

Ben Chapman wrote:
> Everyone:
> 
> I know that this has come up over and over on the list, I just still 
> can't get a handle on it. If I could get some good information from the 
> list, I would like to put together a HOW-TO on this, because I think 
> it's a common goal. I have folders that contain folders and other 
> objects. I want to build a menu along the lefthand-side that shows all 
> the folders with an attribute 'publish' defined, and, we'll show their 
> 'nickname' or 'displayname' properties in place of 'title_or_id' if 
> those are defined. So far, this is easy.
> 
> However, we also want to arbitrarily sort the folders and while the 
> below code works, it doesn't do exactly what I want. We define an 
> integer property 'sort_value', then sort based on sort_value and 
> alternatively title_or_id.
> 
> This works, sort of:
> 
[snip]