Why does setText () change the contentType of a document?

When I change the text, for example. in a document with setText()the document content type is changed to 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'

Even if I create a document and I set it mimetypeexplicitly to text/plain, it changes the type to 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'

The text is processed by the _process_input()class TextField(FileField), and it guesses the type and changes it.

Does the API expect the programmer to know all the guesswork _process_input()? If so, is it documented somewhere?

+4
source share
1 answer

I think your document is an ATContentTypes document.

in this case, mimetype is used by default if the specific mimetype type is not specified in setText:

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

+2

Source: https://habr.com/ru/post/1529804/


All Articles