Platinum Partner

Create, Publish, Hide & Global Disallow A Plone Content Type From Python

Implemented in setuphandlers.py; 
during installation of the product create an object at the root level; 
hide it from the navbar; 
publish it & also do not let the Content Type to be globally allowed. 
context is assumed and Content Type is any. 
Solution:

 
We need these tools: 
>>> from Products.CMFCore.utils import getToolByName
>>> workflow_tool = getToolByName( portal, 'portal_workflow' )
>>> portal_types = getToolByName( portal, 'portal_types' ) 

A sample content type: 
>>> ContentTypeName = 'Archive'

Get the portal root: 
>>> portal = context.getSite()

Create object at the portal root level: 
>>> portal.invokeFactory( ContentTypeName, id='AtTheRootLevel', title='At The Root Level' )

Grab the object:  
>>> AtTheRootLevel = getattr( portal, 'AtTheRootLevel' ) 

Publish it: 
>>> workflow_tool.doActionFor( AtTheRootLevel, 'publish' )

Get the content type object and disallow it globally: 
>>> Archive = getattr( portal_types, 'Archive' )
>>> Archive.global_allow = False 

Remove the object created at the portal root from the main navbar
>>> actions = portal.portal_actions
>>> AtTheRootLevelTab = actions.AtTheRootLevel
>>> AtTheRootLevelTab.setExcludeFromNav( True )
>>> AtTheRootLevelTab.reindexObject()

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}