Likely because when user log in system , is created a object AUTH that contains all informations about current user logged , at login action happen all operations necessary to get user data of database ( including groups informations related )
Then with all this data in "session" don't need verify in database level , because exists a object in "session" with this data. I guess :D , I tried analyse the code's web2py , and the Auth object create a this.user_groups attribute request = current.request session = current.session auth = session.auth self.user_groups = auth and auth.user_groups or {} Then all data about auth.* using "session data" Reference: https://github.com/web2py/web2py/blob/master/gluon/tools.py#L1805 Em sexta-feira, 11 de novembro de 2016 11:22:12 UTC-3, 黄祥 escreveu: > > thanks all for the detail explanation, learn a lot new things today > {{=DIV(auth.user_groups) }} > *result :* > {1L: 'Admin', 2L: 'User'} > > {{=DIV(auth.user_groups.values() ) }} > *result :* > AdminUser > > {{=set(auth.user_groups.values() ) }} > *result :* > set(['Admin', 'User']) > > now about hitting database, just want to clarify in web2py there is > auth.has_membership() > *e.g.* > *controllers/default.py* > """ > *# 1 usually used* > has_membership_admin = auth.has_membership(role = 'Admin') > """ > > *# 2 learn today* > has_membership_admin = 'Admin' in auth.user_groups.values() > > def test(): > table = db.test > grid = SQLFORM.grid(table, deletable = has_membership_admin) > return locals() > > did the #2 is faster than #1 because #2 didn't hit database? > > thanks and best regards, > stifan > -- 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.