You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a RelationChoice is added directly into a dexterity type the value is converted to a RelationValue prior to being saved into the database.
When a RelationChoice is added into a data grid row, the value is stored as the object that was selected but Plone has issues re-loading this object from a cold-start when Plone restarts.
I was able to resolve this by implementing this datagrid converter into my project, you may be able to think of a more elegant way to implement this directly into the datagrid
I will try to create a unit test for this soon which shows the issue in comparison between a regular content type's fields and when this field is inside of a data grid.
import zope.interface
import zope.schema.interfaces
from z3c.form.converter import BaseDataConverter
from z3c.relationfield.interfaces import IRelationChoice
from z3c.relationfield import RelationValue
from zope.intid.interfaces import IIntIds
from collective.z3cform.datagridfield.interfaces import IDataGridField
from zope import component
class GridDataConverter(BaseDataConverter):
""" The usual behaviour for a RelationChoice schema field is for the
value to be stored as a RelationValue in the the ZODB.
The default behaviour by the z3cform datagrid is to store the item
as-is.
As a result a strange bug occurs where the value is saved as an object.
When a cold-start occurs however, the item can not be loaded again as
object's can directly be stored on a RelationChoice
What we've done is converted the RelationChoice schema fields into
RelationValue objects prior to persisting it into ZODB.
"""
zope.component.adapts(zope.schema.interfaces.IList, IDataGridField)
def toWidgetValue(self, value):
for row in value:
for key in row:
if IRelationChoice.providedBy(self.field.value_type.schema[key]):
row[key] = row[key].to_object
return value
def toFieldValue(self, value):
intids = component.queryUtility(IIntIds)
for row in value:
for key in row:
if IRelationChoice.providedBy(self.field.value_type.schema[key]):
row[key] = RelationValue(intids.getId(row[key]))
return value
The text was updated successfully, but these errors were encountered:
When a RelationChoice is added directly into a dexterity type the value is converted to a RelationValue prior to being saved into the database.
When a RelationChoice is added into a data grid row, the value is stored as the object that was selected but Plone has issues re-loading this object from a cold-start when Plone restarts.
I was able to resolve this by implementing this datagrid converter into my project, you may be able to think of a more elegant way to implement this directly into the datagrid
I will try to create a unit test for this soon which shows the issue in comparison between a regular content type's fields and when this field is inside of a data grid.
The text was updated successfully, but these errors were encountered: