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 """ 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', '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. """
Utils:
def makeFieldsInvisible(schema=None, fields=[]): """ Makes schemata fields respective widgets invisible in the edit form. """ 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.2 (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
collective.setuphelpers-0.1.zip
(21.5 kB
view hashes)