Thanks, neither suggestion has helped.
Yarko, I double click on the app to start it. On a Mac an app is just
a directory, and a shell doesn't understand
the specialness of the .app suffix, only the Finder does.
Massimo, the response.flash is always correct, just the label and the
default value of the text field is out of sync.
If I change
session.bene_year = request.post_vars.year
to
session.bene_year = form.post_vars.year
I get a runtime error
AttributeError: 'FORM' object has no attribute 'post_vars'
===
Here's an even simpler version of the bug:
model:
db.define_table('beneficiary',
SQLField('name','string'),
SQLField('year','integer'))
default controller:
def index():
import datetime
# form sets the default year to work on
if not session.bene_year:
session.bene_year = str(datetime.datetime.now().year)
form = FORM('Set Year (current value is '+session.bene_year+') :
',
INPUT(_name='year', _value=session.bene_year,
requires=IS_NOT_EMPTY()),
INPUT(_type='submit'))
# set the default year from the form
if FORM.accepts(form, request.post_vars, session,
formname='form_one'):
session.bene_year = request.post_vars.year
# set the year
response.flash = 'The default year is set to
'+session.bene_year
# fetch the current beneficiaries for the default year
records = SQLTABLE(db
(db.beneficiary.year==session.bene_year).select(db.beneficiary.ALL),
truncate='1024')
return dict(form=form, records=records)
On Mar 18, 11:10 am, mdipierro <[email protected]> wrote:
> I cannot reproduce this. Can you try
>
> session.bene_year = form.post_vars.year
>
> instead of
>
> session.bene_year = request.post_vars.year
>
> and see if it makes any difference?
>
> On Mar 18, 12:43 am, Jim C <[email protected]> wrote:
>
> > I'm just learning web2py and I've got a simple example whose behavior
> > I don't understand. I've got a page with a form on top that sets a
> > session variable holding the default year.
> > On the bottom of the page I've got an SQLTABLE where the records
> > selected should be from the
> > selected year. What I'm observing is that the form on top accepts
> > the year value and the bottom of the page updates but the form on top
> > always seems to be one update behind.
>
> > In the controller:
>
> > def admin_test():
>
> > # form1 sets the default year to work on
> > if not session.bene_year:
> > session.bene_year = datetime.datetime.now().year
>
> > form1 = FORM('Set Year (current value is '+session.bene_year+') :
> > ',
> > INPUT(_name='year', _value=session.bene_year,
> > requires=IS_NOT_EMPTY()),
> > INPUT(_type='submit'))
>
> > # set the default year from the form
> > if FORM.accepts(form1, request.post_vars, session,
> > formname='form_one'):
> > session.bene_year = request.post_vars.year
> > # set the year
> > response.flash = 'The default year is set to
> > '+session.bene_year
>
> > # fetch the current beneficiaries for the default year
> > dbrecords = db(db.beneficiary.year==session.bene_year).select
> > (db.beneficiary.ALL)
> > records = SQLTABLE(dbrecords, truncate='1024')
>
> > return dict(form1=form1, dbrecords=dbrecords, records=records)
>
> > The sequence I'm observing is:
>
> > 1) Initial page view, year is set to 2009. All OK.
> > 2) Enter 2007 and press 'Submit Query'. Page refreshes, db records
> > from 2007 appear below, and
> > form one reads: "Set Year (current value is 2009) : [ 2009 ]".
> > Not OK.
> > 3) Replace 2009 with 2005 and press 'Submit Query'. Page refreshes, db
> > records from 2005 appear below and the form now reads: "Set Year
> > (current value is 2007): [ 2007 ]".
> > 4) etc.
>
> > Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---