user966660
user966660

Reputation: 592

zope.schema List - Save List of lists

did i misunderstand something? I want to save a list of lists, or a set of lists....

I have this

fcurricula = schema.List(
    title=_(u'Curricula'),
    required=False)

I tried to save this:

[
  [261, u'26-BEA', 138, 4, u'h\xf6ren, listen', 4.00, 0, u'655755sa939b9b10'],
  [261, u'26-BEA', 138, 4, u'h\xf6ren, listen', 4.00, 0, u'655755sa939b9b10']
]

But I get following error

Module zope.tales.expressions, line 217, in __call__
Module Products.PageTemplates.Expressions, line 155, in _eval
Module Products.PageTemplates.Expressions, line 117, in render
Module dudal.db.browser.dbimport, line 216, in dudal_fcurricula_import
Module plone.registry.registry, line 47, in __setitem__
Module plone.registry.record, line 83, in _set_value
Module zope.schema._bootstrapfields, line 182, in validate
Module zope.schema._field, line 475, in _validate
Module zope.schema._bootstrapfields, line 309, in _validate
Module zope.schema._bootstrapfields, line 248, in _validate
Module zope.schema._bootstrapfields, line 233, in _validate
Module zope.schema._bootstrapfields, line 209, in _validate
WrongType: ([[261, u'26-BEA', 138, 4, u'h\xf6ren, listen', 4.0, 0, u'655755sa939b9b10'], [261, u'26-BEA', 138, 4, u'h\xf6ren, listen', 4.0, 0, u'655755sa939b9b10']], <type 'set'>, 'value')

Upvotes: 1

Views: 321

Answers (1)

Mathias
Mathias

Reputation: 6839

You need to define the value_type of the list elements. In you case also a list--> nested list.

You may try something like this:

fcurricula = schema.List(
    title=_(u'Curricula'),
    required=False)
    value_type=schema.List(...)

But I don't know if there is a widget for this use case.

From my point of view, the right widget for you ist a datagrid widget. --> https://github.com/collective/collective.z3cform.datagridfield

It stores a list of dictionaries. If you can properly name the columns in your nested list, you can use a List field with value_type="DictRow" with a datagridwidget.

Since you have to define a seperate schema you can also make sure, your list contains valid data.

Upvotes: 2

Related Questions