Back to index

plone3  3.1.7
getBestIcon.py
Go to the documentation of this file.
00001 ## Script (Python) "getBestIcon"
00002 ##title=Find most specific icon for an (sub)object
00003 ##bind container=container
00004 ##bind context=context
00005 ##bind namespace=
00006 ##bind script=script
00007 ##bind subpath=traverse_subpath
00008 from Products.CMFCore.utils import getToolByName
00009 from zExceptions import NotFound
00010 
00011 mtr = getToolByName(context, 'mimetypes_registry', None)
00012 if mtr is None:
00013     return context.getIcon()
00014 lookup = mtr.lookup(context.getContentType())
00015 if lookup:
00016     mti = lookup[0]
00017     try:
00018         context.restrictedTraverse(mti.icon_path)
00019         return mti.icon_path
00020     except (NotFound, KeyError, AttributeError): # Looking for 'NotFound' or KeyError
00021         pass
00022 return context.getIcon()