[Zope] How to control the number of contained items

Casey Duncan c.duncan@nlada.org
Fri, 19 Oct 2001 09:20:07 -0400


On Friday 19 October 2001 03:10 am, Bocquillon  Philippe allegedly wrote:
> Hello,
>
> I would like to know how I can (with Python code) limit to one at most the
> number of items of a given meta type in an ObjectManager object.
> How to disable the "Add <Meta type>" button when there is already one
> object of this meta type ?
>
> Thank you in advance,
>
> Philippe Bocquillon
>

You can create a method all_meta_types in your class to handle this. Since it 
is a method, it could return different meta-types (or no meta types) 
depending on the contents of the instance.

all_meta_types should return a tuple (or possibly a list) of dictionaries of 
the format:

({'name': 'Meta Type Name', 'action': 'manage_addSomethingOrOther'}, ...)

You can also add an optional permission key as well to specify a permission 
needed to add the meta type (if it differs from the permission specified by 
the meta type's class)

hth,
/---------------------------------------------------\
  Casey Duncan, Sr. Web Developer
  National Legal Aid and Defender Association
  c.duncan@nlada.org
\---------------------------------------------------/