The table definition:

db.define_table('student',
    Field('admission_number', 'integer', notnull=True, unique=True),
    Field('name', 'string', length=255, notnull=True))

db.define_table('school_session',
    Field('school_session', 'reference session_master'),
    Field('admission_number', 'integer', notnull=True),
    Field('class_name', 'reference class_master'),
    Field('roll_number', 'integer', notnull=True))



The controller

def add_student_to_session():
    form = FORM(INPUT(_name='admission_number', requires=IS_NOT_EMPTY()),INPUT
(_type='submit'))
    if form.accepts(request.vars, session):
        admission_number = form.vars.admission_number
        row = db.student(db.student.admission_number==admission_number)
        if not row:
            session.flash ='Admission number does not exist. Please check 
and retry.'
            redirect(URL(r=request, f='add_student_to_session'))
        else:
            db.school_session.admission_number.writable = False
            db.school_session.admission_number.default = admission_number
            form = crud.create(db.school_session)
            student = db.student(row.id)
            student_details = crud.update(db.student, student, readonly=True
)

    return locals()The first form takes the input 'admission_number' and 
checks the student database to see if that record exist.
If it does, it creates two forms 'form' and 'student_details'.
'student_details' is read only to show the user that the details being 
entered in the second form is indeed for the required student, to avoid 
problems that may arise due to the fact that the admission_number may exist 
in the database but the user entered the wrong one.

In the view 'add_student_to_session.html', the following code is there
{{extend 'layout.html'}}
{{=form}}
{{=BEAUTIFY(response._vars)}}
it works file and the 'student_details' variable form show up due to the 
BEAUTIFY keyword.

However, when I modify the code to 
{{extend 'layout.html'}}
{{=student_details}}
{{=form}}
{{=BEAUTIFY(response._vars)}}

I get an error report saying that 'student_details not defined'. How can 
that happen when it shows up when BEAUTIFY keyword displays the content of 
the 'student_details' variable just fine?


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to