gpt4 book ai didi

plone - 为什么 setText() 会改变 Document 的 contentType?

转载 作者:行者123 更新时间:2023-12-01 03:51:33 25 4
gpt4 key购买 nike

当我更改文本时,例如在带有 setText() 的文档中Document 的内容类型更改为 text/plain .

In [1]: app.Plone.invokeFactory('Document', 'doc')
Out[1]: 'doc'

In [2]: app.Plone.doc.getContentType()
Out[2]: 'text/html'

In [3]: app.Plone.doc.setText('xyz'); app.Plone.doc.getContentType()
Out[3]: 'text/plain'

In [4]: app.Plone.doc.setText('<abc>xyz</abc>'); app.Plone.doc.getContentType()
Out[4]: 'text/html'

即使我创建了一个文档并设置了 mimetype明确给 text/plain它将类型更改为 text/html .

In [1]: app.Plone.invokeFactory('Document', 'doc', 
text='<abc>xyz</abc>',
mimetype='text/plain')
Out[1]: 'doc'

In [2]: app.Plone.doc.getContentType()
Out[2]: 'text/html'

文本由 _process_input() 处理的 TextField(FileField)类,它猜测类型并更改它。

API是否希望程序员知道 _process_input()的所有猜测? ?如果是,这是在某处记录的吗?

最佳答案

我猜你的 doument 是一个 ATContentTypes 文档。

在这种情况下,除非在 setText 中给出了特定的 mimetype,否则将使用默认的 mimetype:
doc.setText(u"<p>your text</p>", mimetype='text/html')
https://github.com/plone/Products.ATContentTypes/blob/2.2.0/Products/ATContentTypes/content/document.py#L112

对于上传的文档,mimetype 会被猜测
https://github.com/plone/Products.ATContentTypes/blob/2.2.0/Products/ATContentTypes/content/document.py#L137

关于plone - 为什么 setText() 会改变 Document 的 contentType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22148779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com