[Zope] the misc_ dictionary

Martijn Pieters mj@digicool.com
Thu, 15 Feb 2001 13:02:25 +0100


On Thu, Feb 15, 2001 at 11:59:58AM +0100, Erik Enge wrote:
> [azazel@planningsrl.it]
> 
> | Ok... i still don't know if there is a policy for the use of misc_ but
> | i have resolved my problems
> 
> This is how I use it in my __init__.py file in the product directory
> (ie. lib/python/Products/ProductX):
> 
> 
> __init__.py file:
> 
> #####################################################################
> 
> __doc__ = 'Initialize the rs product.'
> __version__='$Revision: 1.1 $'[11:-2]
> 
> from ImageFile import ImageFile
> 
> misc_ = {
> 	'Folder_icon.gif': ImageFile('img/Folder_icon.gif', globals()),
> 	'dtmldoc.gif': ImageFile('img/dtmldoc.gif', globals()),
> 	}
> 
> import rs
> 
> def initialize(context):
> 	"Initialize the product."
> 	try:
> 		context.registerClass(
> 			rs.rs,
> 			constructors = (rs.manage_addrsForm,
> 							rs.manage_addrs)
> 			)
> 		context.registerHelp()
> 		context.registerHelpTitle('Zope/rs 2000 Help')
> 	except:
> 		import sys, traceback, string
> 		type, val, tb = sys.exc_info()
> 		sys.stderr.write(string.join(traceback.format_exception(type, val, tb), ''))
> 		del type, val, tb
> 
> 
> #####################################################################
> 
> 
> This then allows me to do http://myhost/misc_/rs/Folder_icon.gif
> 
> Hope this helps :)

The use of misc_ in the __init__.py of a Product is deprecated for Product
icons though; it is still useful for registering extra icons.

As for your try/except construct, this one of the first things that Shane
Hathaway made unnecessary by hardening the registration process.
Exceptions in the initialize method are now logged or printed to stdout.

Your code could be simplified to:

    from ImageFile import ImageFile
 
    misc_ = {
        'Folder_icon.gif': ImageFile('img/Folder_icon.gif', globals()) 
    }
 
    import rs
 
    def initialize(context):
        "Initialize the product."
        context.registerClass(
            rs.rs, 
            icon='img/dtmldoc.gif',
            constructors=(rs.manage_addrsForm, rs.manage_addrs))

    context.registerHelp()
    context.registerHelpTitle('Zope/rs 2000 Help')

The rs.rs class can the also omit the icon property.

-- 
Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------