source: products/vendor/Products.CacheSetup/current/Products/CacheSetup/Extensions/utils.py @ 3296

Last change on this file since 3296 was 3296, checked in by fenix, 12 years ago

Load Products.CacheSetup?-1.2.1 into vendor/Products.CacheSetup?/current.

  • Property svn:eol-style set to native
File size: 7.6 KB
Line 
1from Products.Archetypes.public import listTypes
2from Products.CMFCore.utils import getToolByName
3from Products.CacheSetup import config
4
5try:
6    from Products.CMFSquidTool import SquidTool
7except ImportError:
8    SquidTool = None
9
10
11def setupConfiglet(portal, out):
12    # see if there's already a cache configlet and try to
13    # delete it
14   
15    portalConf = None
16    try:
17        portalConf = getToolByName(portal, 'portal_controlpanel')
18    except AttributeError:
19        print >>out, "Configlet could not be installed"
20        return
21   
22    portalConf.unregisterConfiglet(config.CONFIGLET_ID)
23
24    try:
25        portalConf.registerConfiglet(
26            config.CONFIGLET_ID,
27            config.TOOL_TITLE,
28            'string:${portal_url}/%s' % config.CACHE_TOOL_ID,
29            '',                 # a condition
30            'Manage portal',    # access permission
31            'Products',         # section to which the configlet should be added:
32                                #(Plone,Products,Members)
33            1,                  # visibility
34            config.PROJECT_NAME,
35            '/misc_/CacheSetup/cachesetup_tool_icon.gif', # icon in control_panel
36            config.TOOL_TITLE,
37            None
38        )
39    except KeyError:
40        pass # Get KeyError when registering duplicate configlet.
41
42def removeConfiglet(portal, out):
43    # remove configlet from portal_controlpanel
44    pcp = getToolByName(portal,'portal_controlpanel')
45    pcp.unregisterConfiglet(config.CONFIGLET_ID)
46
47def installDependencies(portal, out):
48    if SquidTool is None:
49        raise ValueError, 'Please add CMFSquidTool to your Products directory'
50    qi = getToolByName(portal,'portal_quickinstaller')
51    squidtool = getToolByName(portal,'portal_squid',None)
52    if squidtool is None:
53        qi.installProduct('CMFSquidTool', locked=True)
54        print >> out, 'Installed CMFSquidTool'
55    else:
56        qi.notifyInstalled('CMFSquidTool', locked=True)
57        print >> out, 'Lock CMFSquidTool'
58
59def setupWorkflows(portal, out):
60    """Setup workflow
61    """
62    wftool = getToolByName(portal, 'portal_workflow')
63    typeInfo = listTypes(config.PROJECT_NAME)
64    for t in typeInfo:
65        portal_type = t['portal_type']
66        #if portal_type in ['HeaderSet']:
67        #    wftool.setChainForPortalTypes((portal_type,), '')
68        wftool.setChainForPortalTypes((portal_type,), '')
69
70def setupCacheTool(portal, out):
71    cache_tool = getToolByName(portal, config.CACHE_TOOL_ID, None)
72    if cache_tool is None:
73        ps = portal.portal_types.getTypeInfo('Plone Site')
74        allowed_types = ps.getProperty('allowed_content_types')
75        ps._updateProperty('allowed_content_types', tuple(list(allowed_types)+['CacheTool']))
76
77        portal.invokeFactory(id=config.CACHE_TOOL_ID, type_name='CacheTool')
78        cache_tool = getToolByName(portal, config.CACHE_TOOL_ID)
79        cache_tool.reindexObject()
80        ps._updateProperty('allowed_content_types', allowed_types)
81        print >> out, 'Added %s' % config.CACHE_TOOL_ID
82    cache_tool.setTitle(config.TOOL_TITLE)
83    cache_tool.updateInstalledVersion()
84
85def setupFolderViews(portal, out):
86    props_tool = getToolByName(portal, 'portal_properties')
87    site_props = getattr(props_tool, 'site_properties')
88    typesUseViewActionInListings = list(site_props.getProperty('typesUseViewActionInListings'))
89    for portal_type in config.FOLDER_TYPES:
90        if portal_type not in typesUseViewActionInListings:
91            typesUseViewActionInListings.append(portal_type)
92    site_props.manage_changeProperties(typesUseViewActionInListings = typesUseViewActionInListings)
93
94def restoreFolderViews(portal, out):
95    props_tool = getToolByName(portal, 'portal_properties')
96    site_props = getattr(props_tool, 'site_properties')
97    typesUseViewActionInListings = list(site_props.getProperty('typesUseViewActionInListings'))
98    for portal_type in config.FOLDER_TYPES:
99        if portal_type in typesUseViewActionInListings:
100            typesUseViewActionInListings.remove(portal_type)
101    site_props.manage_changeProperties(typesUseViewActionInListings = typesUseViewActionInListings)
102
103def setupSiteProperties(portal, out):
104    props_tool = getToolByName(portal, 'portal_properties')
105    site_props = getattr(props_tool, 'site_properties')
106    navtree_props = getattr(props_tool, 'navtree_properties')
107    try:
108        types_not_searched = list(site_props.types_not_searched)
109    except AttributeError:
110        types_not_searched = []
111    for t in config.TYPES:
112        if not t in types_not_searched:
113            types_not_searched.append(t)
114    use_folder_tabs = list(site_props.use_folder_tabs)
115    if config.TOOL_TYPE in use_folder_tabs:
116        use_folder_tabs.remove(config.TOOL_TYPE)
117    site_props.manage_changeProperties(types_not_searched=tuple(types_not_searched),
118                                       use_folder_tabs=tuple(use_folder_tabs))
119    metaTypesNotToList = list(navtree_props.metaTypesNotToList)
120    if not config.TOOL_TYPE in metaTypesNotToList:
121        metaTypesNotToList.append(config.TOOL_TYPE)
122    navtree_props.manage_changeProperties(metaTypesNotToList=tuple(metaTypesNotToList))
123
124def restoreSiteProperties(portal, out):
125    props_tool = getToolByName(portal, 'portal_properties')
126    site_props = getattr(props_tool, 'site_properties')
127    navtree_props = getattr(props_tool, 'navtree_properties')
128    try:
129        types_not_searched = list(site_props.types_not_searched)
130    except AttributeError:
131        types_not_searched = []
132    for t in config.TYPES:
133        if t in types_not_searched:
134            types_not_searched.remove(t)
135    site_props.manage_changeProperties(types_not_searched=tuple(types_not_searched))
136    metaTypesNotToList = list(navtree_props.metaTypesNotToList)
137    if config.TOOL_TYPE in metaTypesNotToList:
138        metaTypesNotToList.remove(config.TOOL_TYPE)
139    navtree_props.manage_changeProperties(metaTypesNotToList=tuple(metaTypesNotToList))
140
141def setupSquidTool(portal, out):
142    squid_tool = getToolByName(portal, 'portal_squid', None)
143    squid_tool.setUrlExpression('python:object.%s.getUrlsToPurge(object)' % config.CACHE_TOOL_ID)
144
145def restoreSquidTool(portal, out):
146    # get rid of the url expression in portal_squid
147    squid_tool = getToolByName(portal, 'portal_squid', None)
148    if squid_tool:
149        squid_tool.setUrlExpression('')
150    qi = getToolByName(portal, 'portal_quickinstaller', None)
151    qi.notifyInstalled('CMFSquidTool', locked=False)
152
153def setupPortalFactory(portal, out):
154    factory = getToolByName(portal, 'portal_factory', None)
155    if factory is not None:
156        types = factory.getFactoryTypes().keys()
157        for metaType in config.TYPES:
158            if metaType not in types:
159                types.append(metaType)
160        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
161        print >> out, 'Added content types to portal_factory.'
162       
163def restorePortalFactory(portal, out):
164    factory = getToolByName(portal, 'portal_factory', None)
165    if factory is not None:
166        types = factory.getFactoryTypes().keys()
167        for metaType in config.TYPES:
168            if metaType in types:
169                types.remove(metaType)
170        factory.manage_setPortalFactoryTypes(listOfTypeIds = types)
171        print >> out, 'Removed content types from portal_factory.'
172
173def updateSchemas(portal, out):
174    cache_tool = getattr(portal, config.CACHE_TOOL_ID)
175    _updateChangedSchema(cache_tool, None)
176    catalog = getToolByName(portal, 'portal_catalog')
177    catalog.ZopeFindAndApply(cache_tool, obj_metatypes=config.TYPES,
178                             search_sub=True, apply_func=_updateChangedSchema)
179
180def _updateChangedSchema(o, path):
181    if not o._isSchemaCurrent():
182        o._updateSchema()
183
184
Note: See TracBrowser for help on using the repository browser.