Skip to main content

Various simple functions to be used in Plone's setuphandlers

Project description

collective.setuphelpers

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:

      DISPLAY_VIEWS = {
          'Folder': [
              'short-listing',
              'extended-listing'
          ],

          'Document': [
              'article-view',
              'fancy-document-view'
          ]
      }

      @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
      example:
      CUSTOM_ACTIONS = {
          '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:
  EDITOR_SETTINGS = {
      'attributes': {
          'contextmenu': False,
          'link_using_uids': True,
          'allow_captioned_images': True,
          '...': True
      },
      'commands': {
          'install_transforms': True
      },
      'toolbar': {
          'advhr':False,
          'anchor':False,
          'attribs':False,
          'backcolor':False,
          'bold':True,
          'bullist':True,
          'charmap':False,
          'cleanup':False,
          'code':True,
          'copy':False,
          'cut':False,
          'definitionlist':False,
          'emotions':False,
          'external':False,
          'forecolor':False,
          'fullscreen':False,
          'hr':False,
          'iespell':False,
          'image':True,
          'indent':False,
          'insertdate':False,
          'inserttime':False,
          'italic':True,
          'justifycenter':False,
          'justifyfull':False,
          'justifyleft':False,
          'justifyright':False,
          'link':True,
          'media':False,
          'nonbreaking':False,
          'numlist':True,
          'outdent':False,
          'pagebreak':False,
          'paste':False,
          'pastetext':False,
          'pasteword':False,
          'preview':False,
          'print':False,
          'redo':False,
          'removeformat':False,
          'replace':False,
          'save':False,
          'search':False,
          'strikethrough':False,
          'style':True,
          'sub':False,
          'sup':False,
          'tablecontrols':True,
          'underline':False,
          'undo':False,
          'unlink':True,
          'visualaid':False,
          'visualchars':False,
          'width':u'440'
      },
      'styles': [
          'Subheading|h3',
          '...|..'
      ],
      'tablestyles': [
          'Subdued grid|plain',
          '...|...'
      ],
      'linkable': [
          'News Item',
          '...'
      ],
      'containsanchors': [
          'Document',
          '...'
      ],
      'containsobjects': [
          'Folder',
          '...'
      ],
      'imageobjects': [
          'Image',
          '...'
      ],
  }
  """


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

      CONTENT_TYPES_AVAILABILITY = {
          'DISABLE': [
              'Event',
              'Link'
          ],
          'Plone Site': [
              'Folder',
              'Document'
          ]
      }
  """


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):
  """
  Usage:

  registerTransform(portal, 'web_intelligent_plain_text_to_html',
      'Products.intelligenttext.transforms.web_intelligent_plain_text_to_html')

  """


def unregisterTransform(portal, name):
  """
  Usage:

  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': [
              'Folder',
              'CustomFolder'
          ],
          'exclude': [
              'Link',
              'Document',
              'Event'
          ]
      }
  """


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']
  """

Utils:

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
  """

Changelog

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.

Files for collective.setuphelpers, version 0.6.5
Filename, size File type Python version Upload date Hashes
Filename, size collective.setuphelpers-0.6.5.zip (36.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page