Hi all,
I'm quite new to pyramid and deform and I'm trying to achieve something
very simple that I suppose should work OOTB but I can't get it working.
I have a simple schema-based form and I want the fields to get the
selected value from the request once submitted.
Here's the schema:
class MySchema(colander.MappingSchema):
department = colander.SchemaNode(
colander.String(),
default='',
widget=SelectWidget(values=departments),
)
where choices come from an external db trough sqlalchemy. The form works
but on every submit it lose selected value.
So, I tried the deferred approach [1] like this:
@colander.deferred
def deferred_choices_widget(node, kw):
choices = kw.get('choices')
return SelectWidget(values=choices)
@colander.deferred
def deferred_default(node, kw):
return kw['request'].POST.get('department')
class MySchema(colander.MappingSchema):
department = colander.SchemaNode(
colander.String(),
default=deferred_default,
widget=deferred_choices_widget,
)
I noticed that the request was not in 'kw' so I binded it to the schema:
schema = schema.bind(choices=departments,
default=default,
request=self.request)
Now I see the value into deferred_default call and I can get it using
`kw['request'].POST.get('department')` but there is no way to get it
into the form on reload after submit.
I can't find any meaningful step in the docs... what am I missing?
Versions: colander-0.9.8-py2.7, deform-0.9.5-py2.7, pyramid-1.3.3-py2.7
Thanks,
SimO
[1] http://deformdemo.repoze.org/select_with_deferred/
--
You received this message because you are subscribed to the Google Groups
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/pylons-devel?hl=en.