On Wed, 05 Jul 2000 19:42:38 +0300, Itamar Shtull-Trauring
<[EMAIL PROTECTED]> wrote:

>Shane Hathaway wrote:
>
>> The place where this is needed most (IMHO) is for ZClass factories.  So
>> there needs to be a way to create meta type filters through the Web.
>
>Yes, but in Python products too, where you have Items that should only go in
>specific ItemHolders.  This is very common.

I have a beautiful hack to do this for python products......


Firstly, this code goes in your product __init__

def register_xxxx_class(context,klass,**kwargs):
    meta_type = _register_product_specific_type(context,klass,kwargs)
    if meta_type:
        xxxx_meta_types_registry =
xxxx_meta_types_registry+(meta_type,)


def _register_product_specific_type(context,klass,kwargs):
    """Hijack and abuse the product registration system for our own
product-specific
    type. The mechanism for creating instances of this product is
established, but
    the type is not entered in the global availability list.
    """
    # Register the class
    old = Products.meta_types[:]
    apply(context.registerClass,(klass,),kwargs)
    new = Products.meta_types
    if new[:-1]==old:
        # A new meta_type was added to the end of the global list, as
expected.
        # Remove it, and return it
        Products.meta_types = old
        return new[-1]
    else:
        # Something unexpected happened. The safest thing to do is
leave it alone
        return None




Then, in your ObjectManager derived container, add

    def all_meta_types(self):
        return xxxx_meta_types_registry


Then use register_xxx_class(context,...... in place of
context.registerClass.....





Toby Dickenson
[EMAIL PROTECTED]

_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to