Sorry to revive this old thread. But I am trying fix the issue Can't search and add Relations when adding new content ยท Issue #14 ยท Sinar/popolo.contenttypes ยท GitHub
I tried to monkey patch the 'toWidgetValue' but ended up getting 'from_object' Key error on trying to save the dexterity field (politikus.extractives/extractive_concession.py at 58ee456217c9005c233643b95b5f18303c861dbb ยท Sinar/politikus.extractives ยท GitHub).
<monkey:patch
description="Fix z3c.form value error exceptions"
class="plone.app.z3cform.converters.AjaxSelectWidgetConverter"
original="toWidgetValue"
replacement=".converters.toWidgetValue"
/>
# -*- coding: utf-8 -*-
from z3c.form import converter
import six
def toWidgetValue(self, value):
if not value:
return self.field.missing_value
vocabulary = self.widget.get_vocabulary()
tokenized_value = []
for term_value in value:
if vocabulary is not None:
try:
term = vocabulary.getTerm(term_value)
tokenized_value.append(term.token)
continue
except (LookupError, ValueError):
pass
tokenized_value.append(six.text_type(term_value))
return getattr(self.widget, 'separator', ';').join(tokenized_value)
KeyError
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 168, in transaction_pubevents
Module transaction._manager, line 257, in commit
Module transaction._manager, line 134, in commit
Module transaction._transaction, line 267, in commit
Module transaction._transaction, line 333, in _callBeforeCommitHooks
Module transaction._transaction, line 372, in _call_hooks
Module Products.CMFCore.indexing, line 316, in before_commit
Module Products.CMFCore.indexing, line 226, in process
Module Products.CMFCore.indexing, line 48, in reindex
Module Products.CMFCore.CatalogTool, line 368, in _reindexObject
Module Products.CMFPlone.CatalogTool, line 356, in catalog_object
Module Products.ZCatalog.ZCatalog, line 505, in catalog_object
Module Products.ZCatalog.Catalog, line 369, in catalogObject
Module Products.PluginIndexes.unindex, line 242, in index_object
Module Products.PluginIndexes.unindex, line 287, in _index_object
Module Products.PluginIndexes.unindex, line 225, in insertForwardIndexEntry
Module z3c.relationfield.relation, line 89, in __lt__
Module z3c.relationfield.relation, line 37, in from_path
Module plone.app.relationfield.monkey, line 19, in get_from_object
KeyError: 'from_object'