Plone 3.3 - > 4迁移:缺少setup_tool.setImportContext()

时间:2012-04-23 13:21:04

标签: plone

我正在将一些旧产品更新为4.x代码库。

这是旧的Install.py中的常见模式:

def install(self):
    out=StringIO()

    # Install CSS, JS and other GenericProfile stuff
    setup_tool = getToolByName(self, 'portal_setup')
    original_context = setup_tool.getImportContextID()
    setup_tool.setImportContext('profile-Products.NoneMultiSelectionWidget:default')
    setup_tool.runAllImportSteps()

但是,setup_tool.setImportContext()方法不再存在。什么是正确的替换代码?我是否需要更换代码或是否自动获取GenericSetup XML文件?

追溯:

  - __traceback_info__: ('Products.NoneMultiSelectionWidget',)
     File "/Users/moo/code/buildout-cache/eggs/Products.ExternalMethod-2.13.0-py2.6.egg/Products/ExternalMethod/ExternalMethod.py", line 234, in __call__
       return f(*args, **kw)
      - __traceback_info__: ((<PloneSite at /plone>,), {}, None)
     File "/Users/moo/code/x/src/x/Products.NoneMultiSelectionWidget/Products/NoneMultiSelectionWidget/Extensions/Install.py", line 19, in install
       setup_tool.setImportContext('profile-Products.NoneMultiSelectionWidget:default')
   AttributeError: setImportContext

1 个答案:

答案 0 :(得分:3)

我认为在Plone 3中已经弃用了setImportContext,但我不确定。无论如何,不​​应再明确设置导入上下文,而是这样:

setup_tool = getToolByName(self, 'portal_setup')
original_context = setup_tool.getImportContextID()
setup_tool.setImportContext('profilename')
setup_tool.runAllImportSteps()
# ... restore original context ...

现在只是这个:

setup_tool = getToolByName(self, 'portal_setup')
setup_tool.runAllImportStepsFromProfile('profilename')

此外,只要您的软件包只有一个GS配置文件,您根本不需要此Extensions / install.py代码,因为该配置文件将自动获取。