[ Index ]
 

Code source de Kupu-1.3.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plone/kupu_plone_layer/ -> sample-kupu-customisation-policy.py (source)

   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', 'Folder', 'Large Plone Folder'),
  18      mediaobject = ('Image',),
  19      collection = ('Plone Site', 'Folder', 'Large Plone Folder'),
  20      )
  21  
  22  EXCLUDED_HTML = [
  23    {'tags': ('center','span','tt','big','small','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      "Odd row|tr|odd",
  50      "Even row|tr|even",
  51      "Heading cell|th|",
  52  #    'Fancy|div|fancyClass',
  53  #    'Plain|div|plainClass',
  54  )
  55      
  56  LIBRARIES = (
  57      dict(id="root",
  58           title="string:Home",
  59           uri="string:$portal_url}",
  60           src="string:$portal_url}/kupucollection.xml",
  61           icon="string:$portal_url}/misc_/CMFPlone/plone_icon"),
  62      dict(id="current",
  63           title="string:Current folder",
  64           uri="string:$folder_url}",
  65           src="string:$folder_url}/kupucollection.xml",
  66           icon="string:$portal_url}/folder_icon.gif"),
  67      dict(id="myitems",
  68           title="string:My recent items",
  69           uri="string:$portal_url}/kupumyitems.xml",
  70           src="string:$portal_url}/kupumyitems.xml",
  71           icon="string:$portal_url}/kupuimages/kupusearch_icon.gif"),
  72      dict(id="recentitems",
  73           title="string:Recent items",
  74           uri="string:$portal_url}/kupurecentitems.xml",
  75           src="string:$portal_url}/kupurecentitems.xml",
  76           icon="string:$portal_url}/kupuimages/kupusearch_icon.gif")
  77      )
  78  DEFAULT_LIBRARY = 'myitems'
  79  
  80  INSTALL_BEFOREUNLOAD = True
  81  LINKBYUID = False
  82  
  83  tool = getToolByName(context, 'kupu_library_tool')
  84  typetool = getToolByName(context, 'portal_types')
  85  
  86  def typefilter(types):
  87      all_meta_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
  88      return [ t for t in types if t in all_meta_types ]
  89  
  90  print "remove old resources"
  91  types = tool.zmi_get_type_mapping()
  92  tool.deleteResourceTypes([ t for (t,p) in types])
  93  
  94  print "add resources"
  95  for k,v in RESOURCES.items():
  96      tool.addResourceType(k, typefilter(v))
  97  
  98  mappings = tool.zmi_get_type_mapping()
  99  for rname, t in mappings:
 100      print rname, ", ".join(t)
 101  
 102  print "remove old libraries"
 103  libs = tool.zmi_get_libraries()
 104  tool.deleteLibraries(range(len(libs)))
 105  
 106  print "add libraries"
 107  for lib in LIBRARIES:
 108      tool.addLibrary(**lib)
 109  
 110  for lib in tool.zmi_get_libraries():
 111      keys = lib.keys()
 112      keys.remove('id')
 113      keys.sort()
 114      print lib['id']
 115      for k in (keys):
 116          print '   ',k, lib[k]
 117  
 118  tool.zmi_set_default_library(DEFAULT_LIBRARY)
 119  
 120  print "configure kupu"
 121  tool.configure_kupu(
 122      table_classnames = TABLE_CLASSNAMES,
 123      parastyles=PARAGRAPH_STYLES,
 124      html_exclusions = EXCLUDED_HTML,
 125      style_whitelist = STYLE_WHITELIST,
 126      class_blacklist = CLASS_BLACKLIST,
 127      installBeforeUnload=INSTALL_BEFOREUNLOAD,
 128      linkbyuid=LINKBYUID,
 129      )
 130  
 131  return printed


Généré le : Sun Feb 25 15:30:41 2007 par Balluche grâce à PHPXref 0.7