plone / plone.app.registry

provides Plone UI, persistence and GenericSetup integration for plone.registry
https://pypi.org/project/plone.app.registry
2 stars 6 forks source link

JSONField needs a handler for creation via registry.xml #48

Closed 1letter closed 1 year ago

1letter commented 3 years ago

I use the current main branches of

Creation via Code looks good:

def test_json_field_dict_registry(self):

    data = {
        "persons": [
            {"Test": 35, "Name": "green"},
            {"Test": "John Doe", "Name": "red"},
        ]
    }

    f = field.JSONField(title="Test")
    registry = getUtility(IRegistry)
    registry.records["my.addon.settings.persons"] = Record(f, data)

    self.assertEqual(isinstance(f, JSONField), True)

    entries = api.portal.get_registry_record("my.addon.settings.persons")
    self.assertDictEqual(entries, data)

But via registry.xml it fails:

  <record name="my.addon.settings.persons">
    <field type="plone.registry.field.JSONField">
      <title>JSON Data</title>
      <description>store the data in this field, used by Vocabulary</description>
    </field>
    <value />
  </record>
File "/home/plone/my.addon/src-mrd/plone.app.registry/plone/app/registry/exportimport/handler.py", line 79, in importRegistry
    importer.importDocument(body)
   - __traceback_info__: registry/main.xml
  File "/home/plone/my.addon/src-mrd/plone.app.registry/plone/app/registry/exportimport/handler.py", line 125, in importDocument
    self.importRecord(node)
  File "/home/plone/my.addon/src-mrd/plone.app.registry/plone/app/registry/exportimport/handler.py", line 240, in importRecord
    raise TypeError(
   - __traceback_info__: record name: my.addon.settings.persons
TypeError: Field of type plone.registry.field.JSONField used for record my.addon.settings.persons is not supported.

if i look in the handlers.zcml and fields.py, i think we need a little bit code for JSONFields

sneridagh commented 3 years ago

Yeah, I guess you are right. That part is missing, please, would you like/be able to take care of it?

1letter commented 3 years ago

@sneridagh I'll try it