Python 如何通过ZMI在基于灵巧性的内容类型上设置RichText字段?
我试图在ZMI上使用脚本(Python)创建一个collective.nitf.content对象 我使用的代码是:Python 如何通过ZMI在基于灵巧性的内容类型上设置RichText字段?,python,plone,data-migration,zope,dexterity,Python,Plone,Data Migration,Zope,Dexterity,我试图在ZMI上使用脚本(Python)创建一个collective.nitf.content对象 我使用的代码是: from Products.CMFCore.utils import getToolByName news_folder = context.test_folder wf = getToolByName(news_folder, "portal_workflow") id="test_news" news_folder.invokeFactory('collective.ni
from Products.CMFCore.utils import getToolByName
news_folder = context.test_folder
wf = getToolByName(news_folder, "portal_workflow")
id="test_news"
news_folder.invokeFactory('collective.nitf.content', id)
n = news_folder[id]
n.setTitle('Test went OK')
n.setText('The test went OK.')
n.indexObject()
wf.doActionFor(n, "publish")
当我调用n.setTitle()
时,对象创建正常,但当我调用n.setText()
时,会引发以下错误:
Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Shared.DC.Scripts.Bindings, line 322, in __call__
Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
Module Products.PythonScripts.PythonScript, line 344, in _exec
Module script, line 28, in mais_teste
- <PythonScript at /plone/news_folder/test_script>
- Line 28
AttributeError: setText
回溯(最里面的最后一个):
模块ZPublisher.Publish,第138行,在Publish中
模块ZPublisher.mapply,第77行,在mapply中
模块ZPublisher.Publish,第48行,在call_对象中
模块Shared.DC.Scripts.Bindings,第322行,在调用中__
模块Shared.DC.Scripts.Bindings,第359行,在_bindAndExec中
模块产品.PythonScripts.PythonScript,第344行,in_exec
模块脚本,第28行,在mais_teste中
-
-第28行
AttributeError:setText
我做错了什么?我研究了好几天,没有找到这个问题的答案
版本:
- Plone 4.3.3(4308)
- CMF 2.2.7
- 佐佩2.13.22
- Python 2.7.9(默认值,4月 2015年9月14:50:13)[GCC 4.8.3 20140911(Red Hat 4.8.3-9)]
- PIL 2.3.0 (枕头)
text
是一个RichText
字段;您应该使用RichTextValue
:
从plone.app.textfield.value导入RichTextValue
n、 text=RichTextValue(u'The body'、'text/plain'、'text/html')
请看一下测试,特别是模块。谢谢。如果我在ZMI尝试从plone.app.textfield.value导入RichTextValue时没有获得权限异常,那么问题就解决了。您无法在ZMI上访问该模块,因为。那么,有没有其他方法可以设置默认情况下不受信任代码中允许的富文本?如果无法设置文本(即富文本),那么通过脚本(Python)创建NITF项几乎毫无意义。因为我必须将一些内容(10k+)迁移到一个我无法访问文件系统的服务器,也没有在服务器端安装快速导入产品。我没有足够的权力来改变任何安全或企业政策。然后,除了通过ZMI在脚本上创建这样的对象,我别无选择。被要求仅通过ZMI迁移10k个项目,yikes。坏主意。没有测试,没有备份,自找麻烦。