Not sure what the problem is. How are you determining whether the insert 
was successful? Do you flash message after submitting the form? What does 
the view look like?

Also, a few notes on your code:

def new():
>     if(session.auth is not None and session.auth.user.id is not None):
>         user_id = session.auth.user.id
>

No need to refer to session.auth -- just use "auth". In fact, the first 
line can be reduced to:

    if auth.user_id:

auth.user_id will simply be None if the user is not logged in.
 

>         professor_id = db(db.professor.id == user_id).select(
> db.professor.id)[0]['id']
>

The above query doesn't make sense -- you are querying based on the "id" of 
the db.professor table, but then extracting only the very "id" that you 
used in the query. Furthermore, the IDs in the db.professor table will be 
different from those in the db.auth_user table, so it doesn't make sense to 
search for the db.professor record that happens to have the same "id" as 
the currently logged in user (which will be an "id" from the db.auth_user 
table).
 

>         professor_inst_id = db(db.professor.id == 
> professor_id).select(db.professor.institution)[0]['institution']
>

Same problem above.
 

>         form=FORM('Nome da turma:', INPUT(_name='name', 
> requires=IS_NOT_EMPTY()), 
>                   'Disciplina:',INPUT(_name='subject', 
> requires=IS_NOT_EMPTY()), 
>                   T('Professor Id:') ,INPUT(_name='professor_id', 
> _id='professor_id', value=professor_id), 
>                   T('Institution Id') ,INPUT(_name='professor_inst_id', 
> _id='professor_inst_id', value=professor_inst_id), 
>                   INPUT(_type='submit'))
>

Do you want the user to be able to change the professor_id and 
professor_inst_id? Presumably not, as the user would have no idea what IDs 
are associated with each professor and institution. So, don't bother 
including those in the form (unless you're going to provide a way for the 
user to make a selection based on names).
 

>         if form.accepts(request,session):
>             
>             
> db.classroom.insert(institution=request.vars.professor_inst_id, 
> professor=request.vars.professor_id, subject=request.vars.subject, name=
> request.vars.name)
>             response.flash = T('Nova turma criada')
>

Finally, why not just use SQLFORM(db.classroom)? It will handle everything 
for you, including the database insert.

Anthony

-- 
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/d/optout.

Reply via email to