[Grok-dev] Problems rendering zope.schema.List

Luciano Ramalho luciano at ramalho.org
Thu Jul 5 09:19:10 EDT 2007


This is a gotcha that got me before... Philikon helped me: add a
default argument to the list constructor, like this:

        creators = schema.List(title=u"Authors", required=False,
                               value_type=schema.TextLine(), default=[])

The problem is that the list must never be None. When empty, it must be [].

IMHO, it's a usability bug in the Zope3 API. If the list fails
miserably when it's None, then the default=[] should be automatic. Or
is there some ratinonale for the way things are?

Cheers,

Luciano

On 7/5/07, Sebastian Ware <sebastian at urbantalk.se> wrote:
> I am trying some of the more interesting field types in zope.schema.
> I have added a List field to my interface IProtonObject...
>
>    authors = schema.List(title=u'List of Authors', unique=True,
> value_type=schema.TextLine(title=u'Name'))
>
> ...but I get en error when I try to add the object...
>
>    TypeError: iteration over non-sequence
>
> ...I use a simple add class:
>
>    class Add(grok.AddForm):
>      grok.context(ProtonCMS)
>      form_fields = grok.Fields(id=schema.TextLine(title=u'id'))
>      form_fields += grok.AutoFields(ProtonObject)
>
> Traceback:
>
>      return expression(self)
>     - /Users/jhsware/GrokProjects/ProtonCMS/eggs/grok-0.9dev_r77371-
> py2.4.egg/grok/templates/default_edit_form.pt
>     - Line 47, Column 12
>     - Expression: <PathExpr standard:u'widget'>
>    File "/local/zope3.3/lib/python/zope/tales/expressions.py", line
> 217, in __call__
>      return self._eval(econtext)
>    File "/local/zope3.3/lib/python/zope/tales/expressions.py", line
> 211, in _eval
>      return ob()
>    File "/local/zope3.3/lib/python/zope/app/form/browser/
> sequencewidget.py", line 57, in __call__
>      self._update()
>    File "/local/zope3.3/lib/python/zope/app/form/browser/
> sequencewidget.py", line 62, in _update
>      sequence = self._getRenderedValue()
>    File "/local/zope3.3/lib/python/zope/app/form/browser/
> sequencewidget.py", line 128, in _getRenderedValue
>      sequence = list(self._data)
> TypeError: iteration over non-sequence
>
> Mvh Sebastian
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev
>


More information about the Grok-dev mailing list