Back to index

plone3  3.1.7
get_macros.py
Go to the documentation of this file.
00001 ## Script (Python) "get_macros"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##title=
00008 ##parameters=vdata
00009 from Products.CMFPlone.utils import safe_hasattr
00010 
00011 # We need to get the view appropriate for the object in the history, not
00012 # the current object, which may differ due to some migration.
00013 type_info = context.portal_types.getTypeInfo(vdata.object)
00014 
00015 # build the name of special versions views
00016 if safe_hasattr(type_info, 'getViewMethod'):
00017     # Should use IBrowserDefault.getLayout ?
00018     def_method_name = type_info.getViewMethod(context)
00019 else:
00020     def_method_name = type_info.getActionInfo('object/view')['url'].split('/')[-1] or getattr(type_info, 'default_view', 'view')
00021 versionPreviewMethodName = 'version_%s'%def_method_name
00022 versionPreviewTemplate = getattr(context, versionPreviewMethodName, None)
00023 
00024 # check if a special version view exists
00025 if getattr(versionPreviewTemplate, 'macros', None) is None:
00026     # Use the Plone's default view template
00027     
00028     versionPreviewTemplate = context.restrictedTraverse(def_method_name)
00029 
00030 return versionPreviewTemplate.macros['main']