Open mauritsvanrees opened 3 years ago
With the json_compatible
call, the export will have a field value in the assignment like this:
"linkitem1": {
"@type": "Document",
"review_state": "published",
"@id": "http://localhost:9152/plone/water",
"description": "",
"title": "Water"
}
The current portlet importer stores this dictionary directly in the field, instead of turning it into a RelationValue
. So the portlet view gives an error and the edit form does not show any current value.
Turning it into a UID during export, makes it easier on the import side. For best results, I do have to change my portlet template, and change my portlet field definition from RelationChoice
to schema.Choice
, and use the RelatedItemsFieldWidget
. But this particular portlet has 6 relation fields, linkitem1 though linkitem6, so I may want to refactor it to a single schema.List
anyway.
BTW, I am very happy that I can look at example.contenttype
for the various field/widget combinations.
So: shall I make a PR for the portlet export that changes relation values into uuids?
if value and isinstance(value, RelationValue):
value = value.to_object.UID()
I have several relation fields in a portlet. Exporting portlets then fails because a
RelationValue
is not json serialisable:A bit related Is this comment from Philip where he removes some relations code, although I guess this was only active when exporting content, and not portlets.
The following diff in the portlet export code fixes it for me:
The code needs to be more robust, but those are details. I am not sure if this is a reasonable place for this fix or if there is a more general place.
Ah, wait, using this works too:
At least then you get an export without errors, although my earlier code that returns uuids could be preferable in some cases.