I have a small pythonscript dispatcher that inserts a value in request.form and returns a form: class EDIOrderForm(AutoExtensibleForm, form.EditForm). In my EDIOrderForm, I have subclassed getContent and am prefilling the (Customer ID) value found in my request.form. So far, so good.
On the right side is a Choice field where the customer should be able to select from a filtered list of articles, based on theid Customer ID.
This does not work: I can't seem to pass on the customer id to either the binder or the source itself because the context, as seen by either, is not the form but a <NO_VALUE> object. What am I missing here?
line_item_article = schema.Choice(
title = _(
'line_item_article_title',
default=u'Article'
),
required = True,
source = EDIOrderArticlesSourceBinder(),
)
directives.widget(
'line_item_article',
SelectFieldWidget,
allowNewItems = False,
)
The binder is simply:
@implementer(IContextSourceBinder)
class EDIOrderArticlesSourceBinder(object):
""" """
def __call__(self, context):
log.info('%s called with context: %s' % (self, context))
return EDIOrderArticlesSource(context)
and the IQuerySource object returns the correct results when I hardcode the customer number.
Here's what I see in my log:
mypackage.browser.create_edi_order request.form passed to getContent: {'c_hash': 2744360}
mypackage.browser.create_edi_order customer hash: 2744360
mypackage.browser.create_edi_order widgets: None
mypackage.browser.create_edi_order request.form updated after getContent: {'c_hash': 2744360, 'customer_id': 'K 3080'}
mypackage.vocabularies.sources <mdb_mypackage.vocabularies.sources.EDIOrderArticlesSourceBinder object at 0x7fca2681ca90> called with context: <NO_VALUE>
mypackage.vocabularies.sources <mypackage.vocabularies.sources.EDIOrderArticlesSource object at 0x7fca10cb4490> called with context: <NO_VALUE>
mypackage.vocabularies.sources <mypackage.vocabularies.sources.EDIOrderArticlesSource object at 0x7fca10cb4490> is using customer_id: K 9169
[..]
mypackage.browser.create_edi_order request.form passed to getContent: {'c_hash': 2744360, 'customer_id': 'K 3080'}
mypackage.browser.create_edi_order customer hash: 2744360
mypackage.browser.create_edi_order widgets: <z3c.form.field.FieldWidgets object at 0x7fca27f491d0>
mypackage.browser.create_edi_order request.form updated after getContent: {'c_hash': 2744360, 'customer_id': 'K 3080'}