Annotation of kupuMPIWG/plone/kupu_plone_layer/sample-kupu-customisation-policy.py, revision 1.1
1.1 ! dwinter 1: ## Script (Python) "kupu-customisation-policy"
! 2: ##bind container=container
! 3: ##bind context=context
! 4: ##bind namespace=
! 5: ##bind script=script
! 6: ##bind subpath=traverse_subpath
! 7: ##parameters=
! 8: ##title=Kupu Customisation Policy
! 9: ##
! 10:
! 11: # Make a copy of this script called 'kupu-customisation-policy'
! 12: # in any skin folder on your site and edit it to set up your own
! 13: # preferred kupu configuration.
! 14: from Products.CMFCore.utils import getToolByName
! 15:
! 16: RESOURCES = dict(
! 17: linkable = ('Document', 'Image', 'File', 'News Item', 'Event'),
! 18: mediaobject = ('Image',),
! 19: collection = ('Plone Site', 'Folder', 'Large Plone Folder'),
! 20: )
! 21:
! 22: EXCLUDED_HTML = [
! 23: {'tags': ('center','span','tt','big','small','u','s','strike','basefont','font',),
! 24: 'attributes':(),
! 25: 'keep': 1 },
! 26:
! 27: {'tags':(),
! 28: 'attributes': ('dir','lang','valign','halign','border','frame',
! 29: 'rules','cellspacing','cellpadding','bgcolor'),
! 30: 'keep': 1},
! 31:
! 32: {'tags': ('table','th','td'),
! 33: 'attributes': ('width','height'),
! 34: 'keep': 1},
! 35:
! 36: {'tags': '', 'attributes': '' } # Must be dummy entry at end.
! 37: ]
! 38:
! 39: STYLE_WHITELIST = ['text-align', 'list-style-type', 'float']
! 40: CLASS_BLACKLIST = ['MsoNormal', 'MsoTitle', 'MsoHeader', 'MsoFootnoteText',
! 41: 'Bullet1', 'Bullet2']
! 42:
! 43: TABLE_CLASSNAMES = ('plain', 'listing', 'grid', 'data')
! 44:
! 45: PARAGRAPH_STYLES = (
! 46: "Heading|h2|Heading",
! 47: "Subheading|h3|Subheading",
! 48: "Formatted|pre",
! 49: # 'Fancy|div|fancyClass',
! 50: # 'Plain|div|plainClass',
! 51: )
! 52:
! 53: LIBRARIES = (
! 54: dict(id="root",
! 55: title="string:Home",
! 56: uri="string:${portal_url}",
! 57: src="string:${portal_url}/kupucollection.xml",
! 58: icon="string:${portal_url}/misc_/CMFPlone/plone_icon"),
! 59: dict(id="current",
! 60: title="string:Current folder",
! 61: uri="string:${folder_url}",
! 62: src="string:${folder_url}/kupucollection.xml",
! 63: icon="string:${portal_url}/folder_icon.gif"),
! 64: dict(id="myitems",
! 65: title="string:My recent items",
! 66: uri="string:${portal_url}/kupumyitems.xml",
! 67: src="string:${portal_url}/kupumyitems.xml",
! 68: icon="string:${portal_url}/kupuimages/kupusearch_icon.gif"),
! 69: dict(id="recentitems",
! 70: title="string:Recent items",
! 71: uri="string:${portal_url}/kupurecentitems.xml",
! 72: src="string:${portal_url}/kupurecentitems.xml",
! 73: icon="string:${portal_url}/kupuimages/kupusearch_icon.gif")
! 74: )
! 75: DEFAULT_LIBRARY = 'myitems'
! 76:
! 77: INSTALL_BEFOREUNLOAD = True
! 78: LINKBYUID = True
! 79:
! 80: tool = getToolByName(context, 'kupu_library_tool')
! 81: typetool = getToolByName(context, 'portal_types')
! 82:
! 83: def typefilter(types):
! 84: all_meta_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
! 85: return [ t for t in types if t in all_meta_types ]
! 86:
! 87: print "remove old resources"
! 88: types = tool.zmi_get_type_mapping()
! 89: tool.deleteResourceTypes([ t for (t,p) in types])
! 90:
! 91: print "add resources"
! 92: for k,v in RESOURCES.items():
! 93: tool.addResourceType(k, typefilter(v))
! 94:
! 95: mappings = tool.zmi_get_type_mapping()
! 96: for rname, t in mappings:
! 97: print rname, ", ".join(t)
! 98:
! 99: print "remove old libraries"
! 100: libs = tool.zmi_get_libraries()
! 101: tool.deleteLibraries(range(len(libs)))
! 102:
! 103: print "add libraries"
! 104: for lib in LIBRARIES:
! 105: tool.addLibrary(**lib)
! 106:
! 107: for lib in tool.zmi_get_libraries():
! 108: keys = lib.keys()
! 109: keys.remove('id')
! 110: keys.sort()
! 111: print lib['id']
! 112: for k in (keys):
! 113: print ' ',k, lib[k]
! 114:
! 115: tool.zmi_set_default_library(DEFAULT_LIBRARY)
! 116:
! 117: print "configure kupu"
! 118: tool.configure_kupu(
! 119: table_classnames = TABLE_CLASSNAMES,
! 120: parastyles=PARAGRAPH_STYLES,
! 121: html_exclusions = EXCLUDED_HTML,
! 122: style_whitelist = STYLE_WHITELIST,
! 123: class_blacklist = CLASS_BLACKLIST,
! 124: installBeforeUnload=INSTALL_BEFOREUNLOAD,
! 125: linkbyuid=LINKBYUID,
! 126: )
! 127:
! 128: return printed
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>