datagridfield not visible in dexterity through-the-web content type editor

274 Views Asked by At

I've added collective.z3cform.datagridfield to my buildout, see it as active in my site settings; however, I cannot add a field of type datagridfield via the through-the-web editor for a dexterity content type. What am I missing?

1

There are 1 best solutions below

2
On

Extending vangheem's answer: You can provide support for collective.z3cform.datagridfield by providing a field factory, but it will be a hack.

Reason being is, that the collective.z3cform.datagridfield.row.DictRow expects a schema, defining the table rows. This becomes a subform once rendered. The schemaeditor in this instance would need to ask you depending on the field type also for the (table-) schema.

Depending on what solution you are after, you might be able to get away by implementing a field factory with a fixed table schema like this:

from five import grok
from zope import schema
import collective.z3cform.datagridfield.row
import plone.schemaeditor.interfaces
import zope.interface

# example from http://pypi.python.org/pypi/collective.z3cform.datagridfield
class ITableRowSchema(zope.interface.Interface): 
    one = schema.TextLine(title=u"One")
    two = schema.TextLine(title=u"Two")
    three = schema.TextLine(title=u"Three")

# new field factory for the zope.schema.interfaces.IObject
class DataGridFieldFactory(grok.GlobalUtility):
    grok.provides(plone.schemaeditor.interfaces.IFieldFactory)
    # this will show up in the schema editor vocabulary
    title = "DataGridField"

    def __call__(self, *args, **kwargs):
        # that's the horrid part as it will nail your field to this
        # specific schema
        kw = dict(value_type=collective.z3cform.datagridfield.row.DictRow(
            schema=ITableRowSchema))
        kwargs.update(kw)
        return zope.schema.List(*args, **kwargs)

Please have a look into: plone.schemaeditor.fields.py for more information about the field factory.

This will get you a basic datagrid for your content type. What's missing is the widget, which you currently can't be declared AFAIK.