[Grok-dev] sources in forms - multiple select

Thomas Bellembois thomas.bellembois at gmail.com
Thu Aug 20 06:04:03 EDT 2009


On Thu, Aug 20, 2009 at 11:54 AM, Jeroen Michiel <jmichiel at yahoo.com> wrote:

>
>
> Thomas Bellembois-3 wrote:
> >
> > Still the same error:
> > argument of type "ClassOfCompounds" is not  iterable
> >
>
> That's odd...
> Can you post the relevant parts of your code, and perhaps a traceback of
> the
> error?
> --

Yes, thanks for your help.

A part of my interface.py:
class ClassesOfCompoundsSource(BasicSourceFactory):

    def getValues(self):
        return grok.getSite().classOfCompoundsList()

    def getTitle(self, value):
        return value.name

class IMolecule(interface.Interface):
    cas_number = schema.TextLine(title=u"CAS number")
    ce_number = schema.TextLine(title=u"CE number")
    remark = schema.TextLine(title=u"Remark", required = False)

    # THIS WORKS
    classesOfCompounds = schema.Choice(source=ClassesOfCompoundsSource(),
title=u'Classes of compounds')
    # THIS DOES NOT WORKS
    #classesOfCompounds = schema.List(title=u'Classes of compounds',
value_type = schema.Choice(['1', '2', '3']))

A part of my app.py:
class Chimitheque(grok.Application, grok.Container):

    def classOfCompoundsList(self):
        result = []
        for key in self.keys():
            if key.startswith('classOfCompounds_'):
                result.append(self[key])
        return result

Here is the traceback:
Traceback (most recent call last):
  File
"/home/tbellemb/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
line 133, in publish
    result = publication.callObject(request, obj)
  File
"/home/tbellemb/.buildout/eggs/grok-1.0a4-py2.5.egg/grok/publication.py",
line 89, in callObject
    return super(ZopePublicationSansProxy, self).callObject(request, ob)
  File
"/home/tbellemb/.buildout/eggs/zope.app.publication-3.4.3-py2.5.egg/zope/app/publication/zopepublication.py",
line 167, in callObject
    return mapply(ob, request.getPositionalArguments(), request)
  File
"/home/tbellemb/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
line 108, in mapply
    return debug_call(obj, args)
  File
"/home/tbellemb/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
line 114, in debug_call
    return obj(*args)
  File
"/home/tbellemb/.buildout/eggs/grokcore.formlib-1.1-py2.5.egg/grokcore/formlib/components.py",
line 91, in __call__
    return self.render()
  File
"/home/tbellemb/.buildout/eggs/grokcore.formlib-1.1-py2.5.egg/grokcore/formlib/components.py",
line 74, in render
    self.form_result = self._render_template()
  File
"/home/tbellemb/.buildout/eggs/grokcore.view-1.7-py2.5.egg/grokcore/view/components.py",
line 67, in _render_template
    return self.template.render(self)
  File
"/home/tbellemb/.buildout/eggs/grokcore.view-1.7-py2.5.egg/grokcore/view/components.py",
line 228, in render
    return template.pt_render(namespace)
  File
"/home/tbellemb/.buildout/eggs/zope.pagetemplate-3.4.0-py2.5.egg/zope/pagetemplate/pagetemplate.py",
line 115, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations)()
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 271, in __call__
    self.interpret(self.program)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 346, in interpret
    handlers[opcode](self, args)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 824, in do_loop_tal
    self.interpret(block)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 346, in interpret
    handlers[opcode](self, args)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 536, in do_optTag_tal
    self.do_optTag(stuff)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 521, in do_optTag
    return self.no_tag(start, program)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 516, in no_tag
    self.interpret(program)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 346, in interpret
    handlers[opcode](self, args)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 745, in do_insertStructure_tal
    structure = self.engine.evaluateStructure(expr)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/tales.py",
line 696, in evaluate
    return expression(self)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/expressions.py",
line 217, in __call__
    return self._eval(econtext)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/expressions.py",
line 211, in _eval
    return ob()
  File
"/home/tbellemb/.buildout/eggs/zope.app.form-3.4.1-py2.5.egg/zope/app/form/browser/itemswidgets.py",
line 577, in __call__
    return self.template()
  File
"/home/tbellemb/.buildout/eggs/zope.app.pagetemplate-3.4.1-py2.5.egg/zope/app/pagetemplate/viewpagetemplatefile.py",
line 83, in __call__
    return self.im_func(im_self, *args, **kw)
  File
"/home/tbellemb/.buildout/eggs/zope.app.pagetemplate-3.4.1-py2.5.egg/zope/app/pagetemplate/viewpagetemplatefile.py",
line 51, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  File
"/home/tbellemb/.buildout/eggs/zope.pagetemplate-3.4.0-py2.5.egg/zope/pagetemplate/pagetemplate.py",
line 115, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations)()
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 271, in __call__
    self.interpret(self.program)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 346, in interpret
    handlers[opcode](self, args)
  File
"/home/tbellemb/.buildout/eggs/zope.tal-3.4.1-py2.5.egg/zope/tal/talinterpreter.py",
line 822, in do_loop_tal
    iterator = self.engine.setRepeat(name, expr)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/tales.py",
line 682, in setRepeat
    expr = self.evaluate(expr)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/tales.py",
line 696, in evaluate
    return expression(self)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/expressions.py",
line 217, in __call__
    return self._eval(econtext)
  File
"/home/tbellemb/.buildout/eggs/zope.tales-3.4.0-py2.5.egg/zope/tales/expressions.py",
line 211, in _eval
    return ob()
  File
"/home/tbellemb/.buildout/eggs/zope.app.form-3.4.1-py2.5.egg/zope/app/form/browser/itemswidgets.py",
line 558, in choices
    if term.value not in available_values]
TypeError: argument of type 'ClassOfCompounds' is not iterable
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20090820/ad28dea8/attachment-0001.html 


More information about the Grok-dev mailing list