我尝试在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.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
我做错了什么?我研究了好几天,根本没有回答这个问题。
版本:
答案 0 :(得分:4)
collective.nitf是一个基于敏捷的内容类型,所以不需要在这里使用setter,你应该直接将值赋给字段。
另请注意,text
是RichText
字段;你应该使用RichTextValue
:
from plone.app.textfield.value import RichTextValue
n.text = RichTextValue(u'The body.', 'text/plain', 'text/html')
查看测试,特别是test_catalog模块。