Dynamic login_next view

78 views
Skip to first unread message

Christian Espinoza

unread,
May 2, 2013, 12:54:34 PM5/2/13
to web...@googlegroups.com
Hi guys, 
I'm trying to do a different 'first view' for a admin user, and for this, I was modified my db.py file on this way:

if auth.user.first_name == 'admin':
    auth.settings.login_next = URL('admin', 'system')
else:
    auth.settings.login_next = URL('mainboard', 'index')

But seems that on that point the user doesn't exist yet, how can achieve it?

Thanks in advance.
Christian.

Error:

Error ticket for "avl"

Ticket ID

127.0.0.1.2013-05-02.12-47-26.3706ee73-470f-4dd6-bcde-8a400366785c

<type 'exceptions.AttributeError'> 'NoneType' object has no attribute 'first_name'

Versión

web2py™Version 2.4.6-stable+timestamp.2013.04.21.19.50.11
PythonPython 2.7.3: /usr/bin/python (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/avl/models/db.py", line 72, in <module>
if auth.user.first_name == 'admin':
AttributeError: 'NoneType' object has no attribute 'first_name'

Error snapshot help

<type 'exceptions.AttributeError'>('NoneType' object has no attribute 'first_name')


Anthony

unread,
May 2, 2013, 2:22:19 PM5/2/13
to web...@googlegroups.com
Since you won't know the user's name until after they log in, you should instead do:

auth.settings.login_onaccept = lambda user: user.first_name == 'admin' and redirect(URL('admin', 'system'))

Anthony

Christian Espinoza

unread,
May 2, 2013, 3:03:42 PM5/2/13
to web...@googlegroups.com
Thanks Anthony, it was ver useful!


2013/5/2 Anthony <abas...@gmail.com>

--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/eLRKQzv3wd0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages