Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Setting text field in create fails on Dexterity #300

@hvelarde

Description

@hvelarde

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions