[Grok-dev] Schema.List using schema.Choice and Source gives error?

Adam Summers adamsummers1 at me.com
Wed Feb 2 11:49:12 EST 2011

Hi there,

I have a source which looks like this:

def AccountMasterSource(context):
        return(schema.vocabulary.SimpleVocabulary([schema.vocabulary.SimpleTerm(item.__name__, item.name) for item in grok.getSite()['AccountMaster'].values()]))

Which works beautifully here when I have code in an interface as thus:

class IGLLine(interface.Interface):
        """A GL Line"""        
	entryDate = schema.Date(title=u"Date", default=date.today())
        account = schema.Choice(title=u"Account", source=AccountMasterSource)

... but will not work in the following interface ....

class IGLTransactionLine(interface.Interface):
        """This is the subline"""
        account = schema.Choice(title=u"Account", source=AccountMasterSource)
        drcr = schema.Choice(title=u"Debit/Credit", values=['DR', 'CR'], default='DR')

class IGLTransaction(interface.Interface):
        entryDate = schema.Date(title=u"Date", default=date.today())
        transactions = schema.List(title=u"Transactions",
                value_type=schema.Object(title=u'Transactions', schema = IGLTransactionLine),

When I add a GLTransaction, I get the following error (see traceback in attachment).

File '/Users/adamsummers1/.buildout/eggs/zope.schema-3.7.0-py2.6.egg/zope/schema/_field.py', line 481 in _validate_fields
  attribute.validate(getattr(value, name))
File '/Users/adamsummers1/.buildout/eggs/zope.schema-3.7.0-py2.6.egg/zope/schema/_bootstrapfields.py', line 147 in validate
File '/Users/adamsummers1/.buildout/eggs/zope.schema-3.7.0-py2.6.egg/zope/schema/_field.py', line 325 in _validate
  if value not in vocabulary:
TypeError: argument of type 'function' is not iterable

... and its because of the source specified in the schema.Choice.

Is my interface defined the correct way?

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: error.txt
Url: http://mail.zope.org/pipermail/grok-dev/attachments/20110203/f13f5dfb/attachment.txt 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample.py
Type: text/x-python-script
Size: 4071 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20110203/f13f5dfb/attachment.bin 
-------------- next part --------------

I've also included a simplified extract of the code...

Once again, thanks for the help!

More information about the Grok-dev mailing list