The combination of Shane's Refresh product and Steve's code to prevent
multiple names in the product add list is really useful. Thanks, guys!

I've reworked Steve's initialize code so it works for products that have
multiple classes. As an added benefit, you no longer need to specify which
class is being refreshed, so the meta types can be renamed or the code
reused without changing a single line.

Cheers,

Stephen

-------------Here is the code: ----------------------------------------
def initialize(context):
    """Initialize my product"""
    context.registerClass(...)
    context.registerBaseClass(...)

    # Fix Refresh's behaviour of unconditionally reading all class
meta_types.
    # This code extends Steve Spicklemire's fix for products with multiple
classes.
    import Products
    found_meta_types = []
    new_meta_type_list = []
    for mt in Products.meta_types:
        if mt['name'] in found_meta_types:
            pass
        else:
            found_meta_types.append(mt['name'])
            new_meta_type_list.append(mt)
    Products.meta_types = tuple(new_meta_type_list)


-----------------Steve Spicklemire wrote-----------------------------
Debugging products is a pain... restarting Zope all the time is a Pain....

THANK GOD for Shane Hathaway. ;-)

I am delighted to report general success with the Refresh product!  My
only problem is while debugging the process of creating new EMarket
instances, I find that every time I run 'Refresh' I get a new
"EMarket" in the 'Available Objects' popup. A quick test of other
Products shows the same behavior.

Soo... I snooped through the product creation code and found
that Products.meta_types was being unconditionally appended to
every time context.registerClass was called.... so I changed
my initialize to this:

def initialize(context):

    import Products

    context.registerClass(
        EMarket.EMarket,
        permission='Add EMarkets',
        constructors=(EMarket.addEMarketForm,
                      EMarket.addEMarket),
        icon='emarket.gif',
        )

    found_count = 0

    new_products_meta_types = []

    for index in range(len(Products.meta_types)):
        if Products.meta_types[index]['name'] == EMarket.EMarket.meta_type:
            found_count = found_count + 1
            if found_count == 1:
                new_products_meta_types.append( Products.meta_types[index] )
        else:
            new_products_meta_types.append( Products.meta_types[index] )

    Products.meta_types = tuple( new_products_meta_types)

In other words... only include the original version of
EMarket.EMarket.meta_type
in the Product.meta_types tuple... if there are others... leave them out.

...and that seems to have solved the problem....

Does this seem like an OK idea?

thanks,
-steve


_______________________________
Stephen Simmons
HealthArena B.V.
phone +31 20 486 0555
mobile +31 6 1505 3086
[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