本文整理汇总了Python中pyvac.models.User.by_role方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_role方法的具体用法?Python User.by_role怎么用?Python User.by_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.User
的用法示例。
在下文中一共展示了User.by_role方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_view
# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_role [as 别名]
def update_view(self, model, view):
settings = self.request.registry.settings
ldap = False
if 'pyvac.use_ldap' in settings:
ldap = asbool(settings.get('pyvac.use_ldap'))
if view['errors']:
self.request.session.flash('error;%s' % ','.join(view['errors']))
view['groups'] = Group.all(self.session, order_by=Group.name)
view['managers'] = User.by_role(self.session, 'manager')
if ldap:
ldap = LdapCache()
login = self.get_model().login
if login:
view['ldap_user'] = ldap.search_user_by_login(login)
else:
view['ldap_user'] = {}
view['managers'] = ldap.list_manager()
view['units'] = ldap.list_ou()
view['countries'] = Countries.all(self.session,
order_by=Countries.name)
# generate a random password for the user, he must change it later
password = randomstring()
log.info('temporary password generated: %s' % password)
view['password'] = password
view['view_name'] = self.__class__.__name__.lower()
view['myself'] = (self.user.id == self.get_model().id)
示例2: update_view
# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_role [as 别名]
def update_view(self, model, view):
settings = self.request.registry.settings
ldap = False
if 'pyvac.use_ldap' in settings:
ldap = asbool(settings.get('pyvac.use_ldap'))
if view['errors']:
self.request.session.flash('error;%s' % ','.join(view['errors']))
view['groups'] = Group.all(self.session, order_by=Group.name)
view['managers'] = User.by_role(self.session, 'manager')
if ldap:
ldap = LdapCache()
login = self.get_model().login
view['ldap_user'] = {}
if login:
try:
view['ldap_user'] = ldap.search_user_by_login(login)
except UnknownLdapUser:
msg = 'Unknown ldap user %s' % login
self.request.session.flash('error;%s' % msg)
view['managers'] = ldap.list_manager()
view['units'] = ldap.list_ou()
view['teams'] = ldap.list_teams()
uteams = {}
for team, members in view['teams'].iteritems():
for member in members:
uteams.setdefault(member, []).append(team)
view['user_teams'] = uteams.get(view['ldap_user'].get('dn'), [])
view['countries'] = Countries.all(self.session,
order_by=Countries.name)
# generate a random password for the user, he must change it later
password = randomstring()
log.debug('temporary password generated: %s' % password)
view['password'] = password
view['view_name'] = self.__class__.__name__.lower()
view['myself'] = (self.user.id == self.get_model().id)
示例3: test_by_role
# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_role [as 别名]
def test_by_role(self):
from pyvac.models import User
admins = User.by_role(self.session, 'admin')
self.assertEqual(len(admins), 1)