Back to index

plone3  3.1.7
getAddableTypesInMenu.py
Go to the documentation of this file.
00001 ## Script (Python) "getAddableTypesInMenu"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=allowedTypes
00008 ##title=Return a list of the content type ftis filtered by getImmediatelyAddableTypes(), if available.
00009 
00010 context.plone_log("The getAddableTypesInMenu script is deprecated and will be "
00011                   "removed in Plone 4.0.")
00012 
00013 INTERFACE = "Products.CMFPlone.interfaces.ConstrainTypes.IConstrainTypes"
00014 
00015 from Products.CMFCore.utils import getToolByName
00016 itool = getToolByName(context, 'portal_interface')
00017 mtool = getToolByName(context, 'portal_membership')
00018 translate = context.translate
00019 
00020 plone_view = context.restrictedTraverse('@@plone')
00021 folder = plone_view.getCurrentFolder()
00022 
00023 if not itool.objectImplements(folder, INTERFACE):
00024     result = [(translate(ctype.Title()), ctype) for ctype in allowedTypes]
00025     result.sort()
00026     result = [ctype[-1] for ctype in result]
00027     return result
00028 
00029 if mtool.checkPermission('View', folder):
00030     immediateIds = folder.getImmediatelyAddableTypes()
00031     result = [(translate(ctype.Title()), ctype) for ctype in allowedTypes if ctype.getId() in immediateIds]
00032     result.sort()
00033     result = [ctype[-1] for ctype in result]
00034     return result
00035 else:
00036     return []