Ménage.
[Plinn.git] / Products / Plinn / profiles / photo / various.py
1 ## Script (Python) "various.py"
2 ##bind container=container
3 ##bind context=context
4 ##bind namespace=
5 ##bind script=script
6 ##bind subpath=traverse_subpath
7 ##parameters=site
8 ##title=Import various Plinn setting
9 ##
10 from Products.CMFCore.utils import getToolByName
11 from Products.CMFCore.exceptions import BadRequest
12 from Products.Plinn.exceptions import WorkflowException
13 from Products.Plinn.utils import translate as i18ntranslate
14 translate = lambda msg : i18ntranslate(msg, context)
15
16
17 # constructs misc objects
18 # (productName, factory, id)
19 misc=(('StandardCacheManagers', 'manage_addAcceleratedHTTPCacheManager', 'HTTPCache'),
20 ('StandardCacheManagers', 'manage_addRAMCacheManager', 'rcm'),
21 ('GroupUserFolder', 'manage_addGroupUserFolder', 'acl_users'))
22
23
24 dispatcher = site.manage_addProduct
25 for m in misc :
26 try : getattr(dispatcher[m[0]], m[1])(m[2])
27 except : pass
28
29 if site.acl_users.Users.acl_users.encrypt_passwords :
30 site.acl_users.Users.acl_users.manage_setUserFolderProperties(encrypt_passwords=True)
31
32
33 # configure mosaicTool
34 blockTypes = ('Action Box Block', 'Container Block', 'File Block', 'Image Block', 'Mosaic Document',
35 'Section Block', 'Spacer Block', 'Text Block', 'Tree Box Block')
36
37 mostool = getToolByName(site, 'mosaic_tool')
38 addBI = mostool.manage_addProduct['MosaicDocument'].addMosaicBlockInformation
39 for bt in blockTypes :
40 try : addBI(blockType=bt)
41 except BadRequest : pass
42
43 # contents
44 ttool = getToolByName(site, 'portal_types')
45 wtool = getToolByName(site, 'portal_workflow')
46
47 def constructOrSkip(*args, **kw) :
48 try : ttool.constructContent(*args, **kw)
49 except BadRequest : pass
50
51 def addBlockOrSkip(container, *args, **kw) :
52 try : container.addBlock(*args, **kw)
53 except BadRequest : pass
54
55 def doActionForOrSkip(*args, **kw) :
56 try : wtool.doActionFor(*args, **kw)
57 except WorkflowException : pass
58
59 # home page
60 text=[]
61 text.append('<h1>%s</h1>' % translate('Welcome to Plinn!'))
62 text.append('<p>%s</p>' % translate('This is the default home page.'))
63 text.append('<p>%s</p>' % translate('To change the content just select "Edit" in the Tab bar on the top.'))
64 text = '\n'.join(text)
65 constructOrSkip( 'Document', site, 'index_html'
66 , title = translate('Home')
67 , text_format='html'
68 , text=text)
69 doActionForOrSkip(site.index_html, 'direct_publish')
70
71 # default folders
72 constructOrSkip('Huge Plinn Folder', site, 'Members', title = translate('Members'))
73 #constructOrSkip('Huge Plinn Folder', site, 'global_settings', title = translate('Portlets'))
74 if not hasattr(site, 'global_settings') :
75 site.manage_addProduct['OFSP'].manage_addFolder('global_settings')
76 if not site.global_settings.hasProperty('noIndex'):
77 site.global_settings.manage_addProperty('noIndex', True, 'boolean')
78
79 # left boxes
80 constructOrSkip('Mosaic Document', site.global_settings, 'left_boxes', title=translate('Left boxes'))
81 lb = site.global_settings.left_boxes
82 addBlockOrSkip(lb, 'Tree Box Block', 0, id='nav_tree')
83 lb.nav_tree.saveBlock(filteredMetaTypes={'text' : ['Huge Plinn Folder', 'Portfolio', 'Topic']})
84 doActionForOrSkip(lb, 'direct_publish')
85
86 # right boxes
87 constructOrSkip('Mosaic Document', site.global_settings, 'right_boxes', title=translate('Right boxes'))
88 rb = site.global_settings.right_boxes
89 addBlockOrSkip(rb, 'Action Box Block', 0, id='global_actions')
90 rb.global_actions.saveBlock(boxTitle={'text' : translate('Global actions')}, categories={'text' : ['global']})
91 addBlockOrSkip(rb, 'Action Box Block', 0, id='workflow_actions')
92 rb.workflow_actions.saveBlock(boxTitle={'text' : translate('Workflow')}, categories={'text' : ['workflow']})
93 doActionForOrSkip(rb, 'direct_publish')
94
95 # tools settings
96 mtool = getToolByName(site, 'portal_membership')
97 mtool.setMemberAreaPortalType('Huge Plinn Folder')
98
99 gtool = getToolByName(site, 'portal_groups')
100 gtool.setGroupWorkspaceContainerType('Huge Plinn Folder')
101 gtool.setGroupWorkspaceType('Huge Plinn Folder')
102
103 caltool = getToolByName(site, 'portal_calendar')
104 caltool.configureTool(['created', 'modified', 'DateTimeOriginal'], [9, 18])
105
106 pimtool = getToolByName(site, 'portal_image_manipulation')
107 if not pimtool.hasObject('image') :
108 pimtool.manage_addProduct['OFSP'].manage_addFolder('image')
109 if not pimtool.hasObject('tile') :
110 pimtool.manage_addProduct['OFSP'].manage_addFolder('tile')
111
112 ctool = getToolByName(site, 'portal_catalog')
113 if not 'position' in ctool.indexes() :
114 ctool.manage_addProduct['ProxyIndex'].manage_addProxyIndex('position',
115 extra = { 'idx_type' : 'FieldIndex'
116 , 'value_expr' : 'python:object.getParentNode().getObjectPosition(object.getId())'})
117
118 # Caches
119 HTTPCache = site.HTTPCache
120 HTTPCache.manage_editProps(title='Accelerated HTTP Cache',
121 settings={'anonymous_only' : False, 'interval' : 3600,'notify_urls' : []})
122
123 gtool = getToolByName(site, 'portal_groups')
124 gtool.ZCacheable_setManagerId('rcm')
125
126 return 'Various Plinn settings imported'