plone / plone.api

The Plone API
https://6.docs.plone.org/plone.api
Other
86 stars 53 forks source link

Setting text field in create fails on Dexterity #300

Open hvelarde opened 8 years ago

hvelarde commented 8 years ago

The following code fails on Dexterity-based content types (plone.app.contenttypes):

with api.env.adopt_roles(['Manager']):
    obj = api.content.create(
        container=portal,
        type='Document',
        title=u'Pangram',
        text=u'<p>The quick brown fox jumps over the lazy dog</p>',
    )

on Archetypes, the text field is set; on Dexterity, the text field is set as a unicode object leading to the following error:

AttributeError: 'unicode' object has no attribute 'output_relative_to'

the workaround is something like:

def set_text_field(obj, text):
    try:
        obj.setText(text)  # Archetypes
    except AttributeError:
        obj.text = RichTextValue(text, 'text/html', 'text/html')  # Dexterity

where do we handle this? here or in plone.app.contenttypes?

adamcheasley commented 8 years ago

I have seen this myself. I don't know if I would class this a bug in plone.api, but it's certainly not intuitive. I personally would like this to be handled in plone.app.contenttypes, but I may be in the minority.