Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
pyramid + deform: default values and values from request
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Simone Orsi  
View profile  
 More options Oct 4 2012, 3:27 am
From: Simone Orsi <simah...@gmail.com>
Date: Thu, 04 Oct 2012 09:27:42 +0200
Local: Thurs, Oct 4 2012 3:27 am
Subject: Re: pyramid + deform: default values and values from request
ok, it look like I was too tired yesterday night :)

It doesn't work with default schema but with the deferred one it works
smoothly.

Sorry for the noise :P

Anyway, I wonder if this should not be a default behaviour: if the form
renderer find a 'request' element just try to get the value from there?

Wouldn't be useful?

On 10/04/2012 08:58 AM, Simone Orsi wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simone Orsi  
View profile  
 More options Oct 4 2012, 2:58 am
From: Simone Orsi <simah...@gmail.com>
Date: Thu, 04 Oct 2012 08:58:04 +0200
Local: Thurs, Oct 4 2012 2:58 am
Subject: pyramid + deform: default values and values from request
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »