Over a million developers have joined DZone.

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

DZone's Guide to

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

· ·
Free Resource
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. 

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()


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}