我已经按照文档Group-Level Security
写了这些:
def groupfinder(userid, request):
print '#'*80
print userid
role = DBSession.query(Role)....
if role.name == "Admin":
return ['g:admin']
class RootFactory(object):
__acl__ = [
(Allow, Everyone, 'view'),
(Allow, Authenticated, 'edit'),
(Allow, 'g:admin', 'admin')
]
def __init__(self, request):
pass
authn_policy = AuthTktAuthenticationPolicy(
settings['auth.secret'],
callback=groupfinder,
)
它有效,但是加载的每个页面都会重复查询数据库,
是否应该在用户登录时第一次返回权限?
或者也许我做错了......
以及如何知道 mako 等模板中的权限“g:admin”