there are meny problems here.
1) in index you do insert after redirect so the insert is never
executed
2) you use new_student instead of rquest.vars.new_student
3) you access form.vars in action where it is not defined (after
redirect)
4) you denormalize the student name in student_information (soon or
later it will give you trouble)
5) the workflow is not clear.
###########################################
#
ne=IS_NOT_EMPTY(error_message=T('not empty'))
db.define_table('student',
Field('first_name',requires=ne),
Field('middle_initial',requires=ne),
Field('last_name') ,requires=ne,
Field('student_ID',requires=ne),
Field('student_address',requires=ne),
Field('student_phone',requires=ne),
Field('student_email',requires=ne))
db.define_table('student_information',
Field('student_id')
Field('married', 'boolean',default=False),
Field('spouse_name'))
def index():
""" a simple entry form with various types of objects """
form = SQLFORM.factory(Field('student_id',comment='leave blank if
new student'))
if form.accepts(request.vars, session):
if not form.vars.student_id.strip():
redirect(URL(r=request, f='new_student'))
else:
redirect(URL(r=request,
f='student',args=from.vars.student.id))
elif form.errors:
response.flash = 'form is invalid'
else:
response.flash = 'please fill the form'
return dict(form=form, vars=form.vars)
def new_student():
form = crud.create(db.student,
next=URL(r=request,f='insurance_subscriber'))
return dict(form=form)
def student():
thisstudent = db((db.student.student_ID == request.args
(0))).select
()
if not thisstudent:
session.flash='Invalid student id'
redirect(URL(r=request, f='index'))
return dict()
def student_information():
thisstudent = db.student[request.args(0)]
if not thisstudent:
redirect(URL(r=request, f='index'))
thisstudent_information = db
(db.student_information.student_id == thisstudent.id).select()
return dict(thisstudent_information =thisstudent_information)
On Oct 29, 8:10 am, dbb <[email protected]> wrote:
> In all cases the code can not find the data in the database even if it
> exists;
> the redirect is not executed;
> also may be the request.args(0) logic is wrong. Any help on this,
> those experienced web2py users
>
> On Oct 29, 7:03 am, dbb <[email protected]> wrote:
>
> > I have the following data structure, what I want is the following:
> > if the data entered is not in the database to enter it, then redirect
> > to student
> > information to enter the new data for the student. Once the data is
> > in, the next time I enter the same data,the program compares the
> > student ID in the database and if a match is
> > found I want the data to display.
> > But this code is not doing that, need help on this
>
> > ###############################################################
> > database for a student############################
> > db.define_table('student',
> > Field('first_name'),
> > Field('middle_initial'),
> > Field('last_name'),
> > Field('student_ID'),
> > Field('student_address'),
> > Field('student_phone'),
> > Field('student_email'))
>
> > db.define_table('student_information',
> > Field('name' ),
> > Field('student_id')
> > Field('married', 'boolean'),
> > Field('spouse_name'))
> > ####################################################################prompt
> > for a student information###############################
>
> > ef index():
> > """ a simple entry form with various types of objects """
>
> > form = FORM(TABLE(
> > TR('Your First:', INPUT(_type='text', _name='Fname',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Your Middle Initial:', INPUT(_type='text', _name='Mname',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Your Last Bane :', INPUT(_type='text', _name='Lname',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Your student ID Number:', INPUT(_type='text', _name='Pid',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Your email:', INPUT(_type='text', _name='e-mail',
> > requires=IS_EMAIL())),
>
> > TR('Your address:', INPUT(_type='text', _name='Paddress',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Your Phone Number:', INPUT(_type='text', _name='Pphone',
> > requires=IS_NOT_EMPTY())),
>
> > TR('Are You a New student', INPUT(_type='checkbox',
> > _name='new_student')),
>
> > TR('', INPUT(_type='submit', _value='SUBMIT')),
> > ))
> > if form.accepts(request.vars, session):
> > response.flash = 'form accepted'
> > if new_student:
> > redirect(URL(r=request, f='new_student'))
> > db.student.insert(first_name = form.vars.Fname)
> > db.student.insert(last_name = form.vars.Lname)
> > db.student.insert(middle_initial = form.vars.Mname)
> > db.student.insert(student_phone = form.vars.Pphone)
> > db.student.insert(first_name = form.vars.Fname)
> > db.student.insert(student_address = form.vars.Paddress)
> > db.student.insert(first_name =form.vars.Fname)
> > elif redirect(URL(r=request, f='student'))
>
> > elif form.errors:
> > response.flash = 'form is invalid'
> > else:
> > response.flash = 'please fill the form'
> > return dict(form=form, vars=form.vars)
> > ############################################inserting new information
> > of a student######################################################
> > def new_student():
>
> > form = crud.create(db.student,
> > next=URL(r=request,f='insurance_subscriber'))
>
> > return dict(form=form)
>
> > def new_student_information():
>
> > thisstudent = db.student[request.args(0)]
> > if not thisstudent:
> > redirect(URL(r=request, f='index'))
> > db.student_information.student_id.default=thisstudent.id
>
> > form = crud.create(db.student_information)
>
> > return dict(form=form)
>
> > #########################################accessing existing
> > information###########################################################
> > def student():
> > thisstudent = db((db.student.student_ID == form.vars.Pid)).select
> > ()
> > #thisstudent = db.student[request.args(0)]
> > if not thisstudent:
> > redirect(URL(r=request, f='index'))
>
> > return dict( records=records)
>
> > def student_information():
>
> > thisstudent = db.student[request.args(0)]
> > if not thisstudent:
> > redirect(URL(r=request, f='index'))
> > thisstudent_information = db
> > (db.student_information.student_id == thisstudent.id).select()
>
> > return dict(thisstudent_information =
> > thisstudent_information)
> > ################################################################################################################
> > ((=records}} in student.html
> > {{=thisstudent_informationa0 in student_information
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" 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
-~----------~----~----~----~------~----~------~--~---