[Zope] Grouping

Tres Seaver tseaver@palladion.com
Wed, 19 Jan 2000 15:23:43 -0600


"Gregor" <vorlon@iglou.com> wrote:
> 
> I have a bunch of "link" objects (based on a ZClass) in a folder.  Each has a
> "name", "description", "address", and "keywords" property (the latter is of
> type "tokens", which sounds good, but I have no idea if that's what it is for,
> since I have yet to find the docs on those types).
> 
> I can easily get the links sorted by name, e.g., <dtml-in
> "objectItems('Link')" sort=name>
> 
> So how would I get with something like this:
> 
> Keyword1:
>     Link1
>     Link3
>     Link27
>     Link29
> 
> Keyword2:
>     Link4
>     Link5
>     Link19
>     Link27
> 
> Note that Link27 has both Keyword1 and Keyword2 in the Keywords property.
> 
> I could certainly do something like this with an SQL thingy, but I'd just as
> soon use Zope's built in Object Database.  Seems like less of a pain.

I don't know how I would do this in "pure" DTML -- if the Link objects are
cataloged, with the Keywords property cataloged as a KeywordIndex, then you
could wrap it up in nested catalog queries, something like (untested):

  <!-- loop over [ 'Keyword1', 'Keyword2', ... ]
  <ul>
  <dtml-in "Catalog.uniqueValuesFor( 'Keywords' )">
    <dtml-let kwd=sequence-item>
     <li> <dtml-var kwd>: </li>
     <ul>
     <dtml-in "Catalog( Keywords=kwd )">
       <li> <dtml-var id> </li>
     </dtml-in>
     </ul>
  </dtml-in>
  </ul>

-- 
=========================================================
Tres Seaver         tseaver@palladion.com    713-523-6582
Palladion Software  http://www.palladion.com