Skip to main content

Various simple functions to be used in Plone's setuphandlers

Project description


This package provides a few simple functions with common tasks used with initial site content setup.

This does not aim to be as general as possible but it may speed things up.

>>> from collective.setuphelpers.structure import setupStructure
>>> portal = layer['portal']
>>> STRUCTURE = [{'id':'example-id','title':'Example title','type':'Document'}]
>>> setupStructure(portal, STRUCTURE)
>>> portal['example-id']
<ATDocument at /plone/example-id>
>>> portal.manage_delObjects(['example-id'])

You can use subfolders etc.

>>> setupStructure(portal, layer['test_structure'])
>>> portal['testfolder']['item1'].getText()
'<p>Text body</p>'

Various methods:

def registerDisplayViews(portal, views):
  """ Register additional display views for content types based on "views"
      dictionary containing list of additional view ids for each content type.

      @example views dictionary:

          'Folder': [

          'Document': [

      @call from setup handler:

      from tools.sitesetup import registerDisplayViews
      registerDisplayViews(portal, DISPLAY_VIEWS)


def unregisterDisplayViews(portal, views):
  """ Unregister additional display views for content types based on "views"
      dictionary containing list of additional view ids for each content type
      (the same as for registerDisplayViews method).

def setupCatalog(portal, indexes={}, metadata=[]):
  """ Register portal catalog indexes and metadata columns. """

def hideActions(portal, actions):
  """ Hide actions given dict of action categories with values as list of action ids
      example actions:
      HIDE_ACTIONS = {'user':['dashboard'], 'object':['contentrules', 'local_roles']}

def registerActions(portal, actions={}):
  """ Register new portal actions using dict of action attributes like in the following
          '1': { # order in which will be action registered
              'id': 'my-action',
              'category': 'site_actions',
              'title': 'My action',
              'i18n_domain': 'myi18n.domain',
              'url_expr': string:${globals_view/navigationRootUrl}/my-action-view',
              'available_expr': 'python:member is not None'
              'permissions': ('View',),
              'visible': True

def setupTinyMCE(portal, settings):
  """ Configures tinymce wysiwyg editor. Here is an example settings object:
      'attributes': {
          'contextmenu': False,
          'link_using_uids': True,
          'allow_captioned_images': True,
          '...': True
      'commands': {
          'install_transforms': True
      'toolbar': {
      'styles': [
      'tablestyles': [
          'Subdued grid|plain',
      'linkable': [
          'News Item',
      'containsanchors': [
      'containsobjects': [
      'imageobjects': [

def setupCTAvailability(portal, settings):
  """ Use this method to allow/disable content types to be globally or locally addable.
      All non listed content types will be automatically disabled.
      Here is example settings object (NOTE: "DISABLE" key is used to disable
      content types adding globally):

          'DISABLE': [
          'Plone Site': [

def setupHTMLFiltering(portal, settings):
  """ Update html filtering configlet settings, by passing dict of settings as in the
      following example for enabling embed html content in the richtext:

      HTML_FILTER = {
          'remove': {
              'nasty': ['embed', 'object'],
              'stripped': ['object', 'param'],
              'custom': []
          'add': {
              'nasty': [],
              'stripped': [],
              'custom': ['embed']

      NOTE: you can ommit empty lists

def registerTransform(portal, name, module):

  registerTransform(portal, 'web_intelligent_plain_text_to_html',


def unregisterTransform(portal, name):

  unregisterTransform(portal, 'web_intelligent_plain_text_to_html')


def setHomePage(portal, view_name):
  """ Set default view for the site root. """

def setupNavigation(portal, settings):
  """ Use this method to exclude/include content types from navigation  globally.
      Here is example settings object:

      NAVIGATION = {
          'include': [
          'exclude': [

def hidePortletTypes(portal, portlets=[]):
      Hides portlets from the portlet management pages.
      @param: portlets - list of portlet idenifiers used in portlets.xml to register them

      example: portlets=['portlets.Calendar', 'portlets.Classic']

def registerResourceBundle(portal, bundles={}):
      Register resource registry bundles for themes (skin layers).
      @param: bundles - dict of skin layers with list of bundles

      example: RESOURCE_BUNDLES = {
          'MySkin': ['default', 'jquery', 'jquerytools'],
          'OtherSkin': ['default']

def unregisterResourceBundle(portal, layers=[]):
      Unregister custom resource registry bundles for themes (skin layers).
      @param: layers - list of layers for which will be custom bundles unregistered so the skin layer will use only 'default' bundle.

      example: BUNDLES_TO_REMOVE = ['MySkin', 'OtherSkin']


def makeFieldsInvisible(schema=None, fields=[]):
  """ Makes schemata fields respective widgets invisible in the view page or edit form.

      @schema: Archetypes schema object
      @fields: list of field ids/names

def changeFieldsSchemata(schema=None, fields=[]):
  """ Moves fields into different schemata parts like categorisation or settings etc.
      "fields" parameter is expected to be a list of dicts with key: (field) id and
      (schemata id) schemata



0.6.3 (2013-03-12)

  • added class_blacklist and style_whitelist to setupHTMLFiltering [naro]

0.6.2 (2012-09-23)

  • setupStructure accepts base_path parameter which allows to set filesystem path for files and images [naro]

0.6.1 (2012-01-10)

  • fixed broken package in use with plone < 4.2.x by ImportError of IResourceRegistriesSettings [lzdych]

0.6 (2012-01-09)

  • added registerResourceBundle and unregisterResourceBundle [lzdych]

0.5 (2012-01-09)

  • added enableUserPwdChoice method [lzdych]

  • registerActions now accepts available_expr attribute for each action [lzdych]

  • fixed: setupCTAvailability method fails when trying to disable not installed content type [lzdych]

0.4 (2011-10-13)

  • added method for hiding portlets from the portlets management pages [lzdych]

0.3 (2011-10-03)

  • fixed: TinyMCE setuphandler clears “Resource Types” settings if ommited from helper method parameter [lzdych]

0.2.1 (2011-08-18)

  • added a lot of new helper methods and improved readme ;-)

0.1 (2011-06-15)

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (36.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page