Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using collective.z3cform.datagridfield with plone.app.registry and GenericSetup

Plone 4.2.0.1, plone.app.registry 1.1, plone.supermodel 1.1.1, collective.z3cform.datagridfield 0.11

I am trying to use collective.z3cform.datagridfield for a plone.app.registry field but having trouble actually setting values for it. The documentation doesn't seem to say much other than to use collective.z3cform.datagridfield.registry.DictRow for a Persistent version for the registry.

For reference, my class looks like this:

class IMySchema(form.Schema):
  code = schema.TextLine(title = _(u"Code"), required=False)
  name = schema.TextLine(title = _(u"Name"), required=False)

from collective.z3cform.datagridfield.registry import DictRow
class IMySettings(form.Schema):
  """ """
  form.widget(display_fields=DataGridFieldFactory)
  display_fields = schema.List(
                     title = _(u"Display Fields"),
                     description = _(u"The fields that will be displayed in view and edit pages"),
                     value_type=DictRow(title=_(u"Field"), schema=IMySchema),
                     required=False,
                     )

I can set a blank value with GenericSetup, and my control panel form that interacts with this registry works. But I can't get GenericSetup to import values from registry.xml for this record. Entering a value TTP and exporting it with GenericSetup yields the following:

<registry>
  <record field="display_fields" interface="my.product.interfaces.settings.IMySettings" name="my.product.interfaces.settings.IMySettings.display_fields">
    <field type="plone.registry.field.List">
      <description>The fields that will be displayed in view and edit pages</description>
      <required>False</required>
      <title>Display Fields</title>
    </field>
    <value>
      <element>{'code': u'authors', 'name': u'Authors'}</element>
    </value>
  </record>
</registry>

But if I try to import it I get an error!

TypeError: ('Could not adapt', None, <InterfaceClass zope.schema._bootstrapinterfaces.IFromUnicode>)

That's this line in plone.supermodel.utils "converter = IFromUnicode(field)" and in the debugger I see that the value for 'field' is actually None.

So, what is the proper way to handle registry.xml for datagridfields? Or am I going to have to add records programmatically in setuphandlers.py or something? I'm fairly new to using the registry and plone.supermodel, and given that the field says None I would not be surprised if my registry.xml is simply wrong.

like image 342
Esoth Avatar asked Nov 29 '25 21:11

Esoth


1 Answers

I think the problem is that you are declaring code and name as schema.TextLine (unicode) but you are using a string on the registry; try the following:

{u'code': u'authors', u'name': u'Authors'}

like image 179
hvelarde Avatar answered Dec 02 '25 11:12

hvelarde