[Zope-dev] Unique meta_types in a folder

Bill Anderson bill@libc.org
Fri, 17 Mar 2000 14:06:36 -0700


Jason Spisak wrote:
> 
> Zopists,
> 
> Is there anyway to create a list of unique meta_types in a folder
> without knowing them before hand.
> 
> I would hate to pack them into a REQUEST variable throught iteration
> because that would take forever.
> 
> Some thing like
> 
> <dtml-in possible_types>
>  <dtml-in "objectValues(_['sequence-item'])">
>   <dtml-var mycode>
>  </dtml-in>
> </dtml-in>
> 
> I am trying to let the viewer sort the view by meta_type but only have
> the meta_type they ask for show up.  Just like the UniqueValuesfor in
> the Catalog only for a Folder.
> 
> All my best,
> 



		"""Tested Code Follows"""
Sorting by meta_type is easy:
<dtml-in "objectValues()" sort=meta_type>
  <dtml-var meta_type> &nbsp; <dtml-var title_or_id>
</dtml-in objectValues>

Now, I presume you build the display form a search form, or a link?
If so, let's assume you assign the meta_type form variable a name of
'Type'.

<dtml-in "objectValues(_['Type'])" sort=meta_type>
  <br> <a href="<dtml-var absolute_url>"> <dtml-var title_or_id> </a> is
a <dtml-var meta_type>
</dtml-in objectValues>

Will display only the types in a given folder.

To build that list, you could use a Python method (tested) or an
External Method (untested)
and do:
-------------------
possibles=[]
for type in self.objectValues():
	if possibles.count(type.meta_type):
		continue
	else:
		possibles.append(type.meta_type)
return possibles
---------------------

In my testing, I called this "get_meta_types".
to use:
<dtml-in get_meta_types>
	<dtml-var sequence-item>
</dtml-in get_meta_types>

So, I have A DTML Document:
<dtml-if Type>
	<p>Listed by type of object:
	<dtml-in "PARENTS[0].objectValues(_['Type'])" sort=meta_type>
		<br><dtml-var meta_type> &nbsp;&nbsp; <dtml-var title_or_id>
	<dtml-else>
		<p> Sorry, no matches found.
	</dtml-in>

<dtml-else>

	<dtml-in get_meta_types>
		<br><a href=<dtml-var id>?Type=<dtml-var sequence-item
url_quote>><dtml-var sequence-item></a>
	</dtml-in all_meta_types>
</dtml-if Type>

which will provide a list of possible types, authenticated by user,
which when clicked upon, will give a list of objects that match that
chosen meta_type.

"""End tested code"""

Speed was just fine for me. Fit into HTML as needed,modify to suit your
needs, YMMV, yadda-yadda. ;)

Also, there is  http://www.zope.org/Members/AlexR/SelectionLists which,
while it doesn't give exactly what you are looking for, does have
related items, so I referenced it. :)

-- 
In flying I have learned that carelessness and overconfidence are 
usually far more dangerous than deliberately accepted risks. 
          -- Wilbur Wright in a letter to his father, September 1900