I have a behavior with a RichText field that displays the backreferences to site editors. i.e. not stored on the content object.
The field is only displayed in edit mode (as a temporaty workaround) to mitigate my inability to display it in view mode in a separate tab, see this post: Tabbed view for default CT
@provider(IFormFieldProvider)
class IBackReferences(model.Schema):
"""
"""
model.fieldset(
'backreferences',
label=_(u'Back References'),
fields=[
'backreferences'
]
)
backreferences = RichText(
title=_(u'Back References'),
description=_(u''),
required=False,
#readonly=True,
)
form.mode(IEditForm, backreferences='display')
and
@implementer(IBackReferences)
@adapter(IBackReferencesMarker)
class BackReferences(object):
def __init__(self, context):
self.context = context
@property
def backreferences(self):
relationvalues = get_referers_list(self.context, True)
brains = get_brains_for_relation_ids(self.context, relationvalues, sort_key='Title')
html_result_list = ['<li><a href="%s">%s</a></li>' % (brain.getURL(), brain.Title) for brain in brains]
return Markup(u'<ul>%s</ul>' % '\n'.join(html_result_list))
The edit view shows my backreferences for existing content. But editors can not add new content, plone fails with the second traceback.
If I use the @ComputedAttribute decorator on backreferences
then content can be added but when the document is edited again, Plone fails with the first traceback.
I have other use cases where this approach does work. I just realize that there is no field named "image" in that behavior...
@ComputedAttribute
def image(self):
image_link = getattr(self.context.aq_explicit, 'related_image', False)
linked_image = image_link and self.context.related_image.to_object.image or ''
return linked_image