Skip to main content

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

Contributors:

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

Release files for collective.setuphelpers 0.6.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collective.setuphelpers 0.6.5
File Size Uploaded
collective.setuphelpers-0.6.5.zip 36.3 kB Details

Release files / collective.setuphelpers-0.6.5.zip

Download URL collective.setuphelpers-0.6.5.zip
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
78070b4bd3cadbfe733e6a4b39978082e41563b8ccf257dd0daf94aa830ff506
BLAKE2b-256 checksum
How to use checksums
6d5f5117afe7e296e911cb4f6c51520e0ba5bc0fe8257f9ea91aafba0b56e864
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6.5 This release

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page