Updating auth_user and displaying current data

104 views
Skip to first unread message

lesssugar

unread,
Jun 22, 2013, 10:06:31 AM6/22/13
to web...@googlegroups.com
I'm trying to update first_name and last_name of auth_user table. The update form works ok, the respective user record gets updated but the {{=auth.user.first_name}} and {{=auth.user.last_name}} remain unchanged in the view. Guess it's a cache issue but not sure how to make my way around it.

controller:

db.auth_user.email.writable = db.auth_user.email.readable = False
db.auth_user.password.writable = db.auth_user.password.readable = False

edit_fullname = crud.update(db.auth_user, request.args(0), deletable=False, next=(URL('seafarer', 'profile')), _class='formstyle')

return dict(edit_fullname=edit_fullname)

the form is just this

{{extend 'layout.html'}}
{{=edit_fullname}}

respective view line

<li id="full_name"><h1>{{=auth.user.first_name}} {{=auth.user.last_name}}</h1></li>




Anthony

unread,
Jun 22, 2013, 10:30:04 AM6/22/13
to web...@googlegroups.com
auth.user is just a reference to session.auth.user. Once you log in, session.auth.user does not change throughout the session, so if you update the user record in the database, that will not affect auth.user. If you want to update auth.user as well, you have to do so manually. One option might be to add an ._after_update callback to the db.auth_user table (maybe we should add this as an option to Auth so it happens automatically).

Anthony

Anthony

unread,
Jun 22, 2013, 10:59:17 AM6/22/13
to web...@googlegroups.com
Also, note that if you use auth.profile() instead of constructing your own update form, auth.user will get updated as well, so you might consider switching to auth.profile().

Anthony

lesssugar

unread,
Jun 22, 2013, 11:13:45 AM6/22/13
to web...@googlegroups.com
auth.profile() solved it. Thanks a lot.
Reply all
Reply to author
Forward
0 new messages