Back to index

plone3  3.1.7
sample-kupu-customisation-policy.py
Go to the documentation of this file.
00001 ## Script (Python) "kupu-customisation-policy"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=
00008 ##title=Kupu Customisation Policy
00009 ##
00010 
00011 # Make a copy of this script called 'kupu-customisation-policy'
00012 # in any skin folder on your site and edit it to set up your own
00013 # preferred kupu configuration.
00014 from Products.CMFCore.utils import getToolByName
00015 
00016 LINKABLE_BLACKLIST = (
00017     'ATBooleanCriterion',
00018     'ATCurrentAuthorCriterion',
00019     'ATDateCriteria',
00020     'ATDateRangeCriterion',
00021     'ATListCriterion',
00022     'ATPathCriterion',
00023     'ATPortalTypeCriterion',
00024     'ATReferenceCriterion',
00025     'ATRelativePathCriterion',
00026     'ATSelectionCriterion',
00027     'ATSimpleIntCriterion',
00028     'ATSimpleStringCriterion',
00029     'ATSortCriterion',
00030     'ChangeSet',
00031     'CMF Document',
00032     'CMF Event',
00033     'CMF Favorite',
00034     'CMF File',
00035     'CMF Image',
00036     'CMF Link',
00037     'CMF News Item',
00038     'Discussion Item',
00039     'Favorite',
00040     'Link',
00041     'TempFolder',
00042 )
00043 RESOURCES = dict(
00044     linkable = ('blacklist', LINKABLE_BLACKLIST),
00045     mediaobject = ('whitelist', ('Image',)),
00046     collection = ('whitelist', ('Plone Site', 'Folder', 'Large Plone Folder')),
00047     containsanchors = ('whitelist', ('Document', 'News Item', 'Event')),
00048     )
00049 
00050 EXCLUDED_HTML = [
00051   {'tags': ('center','tt','big','small','basefont','font',),
00052    'attributes':(),
00053    'keep': 1 },
00054   
00055   {'tags':(),
00056   'attributes': ('lang','valign','halign','border','frame',
00057       'rules','cellspacing','cellpadding','bgcolor'),
00058    'keep': 1},
00059 
00060   {'tags': ('table','th','td'),
00061    'attributes': ('width','height'),
00062    'keep': 1},
00063 
00064    {'tags': '', 'attributes': '' } # Must be dummy entry at end.
00065 ]
00066 
00067 STYLE_WHITELIST = ['text-align', 'list-style-type', 'float']
00068 CLASS_BLACKLIST = ['MsoNormal', 'MsoTitle', 'MsoHeader', 'MsoFootnoteText',
00069         'Bullet1', 'Bullet2']
00070 
00071 TABLE_CLASSNAMES = ('plain', 'listing', 'grid', 'data')
00072 
00073 PARAGRAPH_STYLES = (
00074     "Heading|h2",
00075     "Subheading|h3",
00076     "Literal|pre",
00077     "Discreet|p|discreet",
00078     "Pull-quote|div|pullquote",
00079     "Call-out|p|callout",
00080     "Highlight|span|visualHighlight",
00081     "Odd row|tr|odd",
00082     "Even row|tr|even",
00083     "Heading cell|th|",
00084 #    'Fancy|div|fancyClass',
00085 #    'Plain|div|plainClass',
00086 )
00087     
00088 LIBRARIES = (
00089     dict(id="root",
00090          title="string:Home",
00091          uri="string:${globals_view/navigationRootUrl|portal_url}",
00092          src="string:${globals_view/navigationRootUrl|portal_url}/kupucollection.xml",
00093          icon="string:${globals_view/navigationRootUrl|portal_url}/misc_/CMFPlone/plone_icon"),
00094     dict(id="current",
00095          title="string:Current folder",
00096          uri="string:${folder_url}",
00097          src="string:${folder_url}/kupucollection.xml",
00098          icon="string:${folder/getIcon}"),
00099     dict(id="myitems",
00100          title="string:My recent items",
00101          uri="string:${portal_url}/kupumyitems.xml",
00102          src="string:${portal_url}/kupumyitems.xml",
00103          icon="string:${portal_url}/kupuimages/kupusearch_icon.gif"),
00104     dict(id="recentitems",
00105          title="string:Recent items",
00106          uri="string:${portal_url}/kupurecentitems.xml",
00107          src="string:${portal_url}/kupurecentitems.xml",
00108          icon="string:${portal_url}/kupuimages/kupusearch_icon.gif")
00109     )
00110 DEFAULT_LIBRARY = 'current'
00111 
00112 INSTALL_BEFOREUNLOAD = False
00113 LINKBYUID = False
00114 CAPTIONING = False
00115 
00116 tool = getToolByName(context, 'kupu_library_tool')
00117 typetool = getToolByName(context, 'portal_types')
00118 
00119 # This code generates preview URLs automatically from the most
00120 # appropriately sized image (if you have PIL installed) or just an
00121 # image field (if you don't).
00122 #
00123 # If you have content types which don't always have an image, or if
00124 # this picks the wrong preview URL, you might want to change these
00125 # expressions.
00126 PREVIEW_EXPR = 'string:${object_url}/%s'
00127 PREVIEW = [ { 'portal_type': type,
00128     'expression': PREVIEW_EXPR % image,
00129     'normal': None,
00130     'scalefield': image.split('_',1)[0],
00131     'classes': '',
00132     'mediatype': 'image',
00133     }
00134             for (type, image) in tool.getPreviewable() ]
00135 # e.g. PREVIEW=[{'portal_type': 'Image',
00136 #                'expression':'string:${object_url}/image_thumb'
00137 #                'normal': 'string:$object_url',
00138 #                'scalefield': 'image' }]
00139 
00140 for p in PREVIEW:
00141     print p['portal_type'], p['expression']
00142 
00143 print "add preview actions"
00144 tool.updatePreviewActions(PREVIEW)
00145 
00146 
00147 def typefilter(types):
00148     all_meta_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
00149     return [ t for t in types if t in all_meta_types ]
00150 
00151 print "remove old resources"
00152 types = tool.zmi_get_resourcetypes()
00153 tool.deleteResourceTypes([ t.name for t in types])
00154 
00155 print "add resources"
00156 for k,(mode,types) in RESOURCES.items():
00157     tool.addResourceType(k, typefilter(types), mode=mode)
00158 
00159 mappings = tool.zmi_get_resourcetypes()
00160 for t in mappings:
00161     print t.name, ", ".join(t.types)
00162 
00163 print "remove old libraries"
00164 libs = tool.zmi_get_libraries()
00165 tool.deleteLibraries(range(len(libs)))
00166 
00167 print "add libraries"
00168 for lib in LIBRARIES:
00169     tool.addLibrary(**lib)
00170 
00171 for lib in tool.zmi_get_libraries():
00172     keys = lib.keys()
00173     keys.remove('id')
00174     keys.sort()
00175     print lib['id']
00176     for k in (keys):
00177         print '   ',k, lib[k]
00178 
00179 tool.zmi_set_default_library(DEFAULT_LIBRARY)
00180 
00181 print "configure kupu"
00182 tool.configure_kupu(
00183     table_classnames = TABLE_CLASSNAMES,
00184     parastyles=PARAGRAPH_STYLES,
00185     html_exclusions = EXCLUDED_HTML,
00186     style_whitelist = STYLE_WHITELIST,
00187     class_blacklist = CLASS_BLACKLIST,
00188     installBeforeUnload=INSTALL_BEFOREUNLOAD,
00189     linkbyuid=LINKBYUID,
00190     captioning=CAPTIONING,
00191     )
00192 
00193 return printed