本文整理汇总了Python中pyvac.models.Request.all_for_admin_per_country方法的典型用法代码示例。如果您正苦于以下问题:Python Request.all_for_admin_per_country方法的具体用法?Python Request.all_for_admin_per_country怎么用?Python Request.all_for_admin_per_country使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.Request
的用法示例。
在下文中一共展示了Request.all_for_admin_per_country方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import all_for_admin_per_country [as 别名]
def render(self):
req_list = {'requests': [], 'conflicts': {}}
requests = []
if self.user.is_admin:
country = self.user.country
requests = Request.all_for_admin_per_country(self.session,
country)
# check if admin user is also a manager, in this case merge all
# requests
requests_manager = Request.by_manager(self.session, self.user)
# avoid duplicate entries
req_to_add = [req for req in requests_manager
if req not in requests]
requests.extend(req_to_add)
elif self.user.is_super:
requests = Request.by_manager(self.session, self.user)
req_list['requests'] = requests
# always add our requests
for req in Request.by_user(self.session, self.user):
if req not in req_list['requests']:
req_list['requests'].append(req)
# split requests by past/next
today = datetime.now()
past_req = [req for req in req_list['requests']
if req.date_to < today
and req.status != 'PENDING']
next_req = [req for req in req_list['requests']
if req not in past_req]
req_list['past'] = past_req
req_list['next'] = next_req
# only retrieve conflicts for super users
# only retrieve conflicts for next requests, not past ones
if req_list['next'] and self.user.is_super:
conflicts = {}
settings = self.request.registry.settings
use_ldap = False
if 'pyvac.use_ldap' in settings:
use_ldap = asbool(settings.get('pyvac.use_ldap'))
if use_ldap:
ldap = LdapCache()
users_teams = {}
for team, members in ldap.list_teams().iteritems():
for member in members:
users_teams.setdefault(member, []).append(team)
conflicts = self.get_conflict_by_teams(req_list['next'],
users_teams)
else:
conflicts = self.get_conflict(req_list['next'])
req_list['conflicts'] = conflicts
return req_list
示例2: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import all_for_admin_per_country [as 别名]
def render(self):
req_list = {'requests': [], 'conflicts': {}}
requests = []
if self.user.is_admin:
country = self.user.country
requests = Request.all_for_admin_per_country(self.session,
country)
# check if admin user is also a manager, in this case merge all
# requests
requests_manager = Request.by_manager(self.session, self.user)
# avoid duplicate entries
req_to_add = [req for req in requests_manager
if req not in requests]
requests.extend(req_to_add)
elif self.user.is_super:
requests = Request.by_manager(self.session, self.user)
if requests:
conflicts = {}
settings = self.request.registry.settings
use_ldap = False
if 'pyvac.use_ldap' in settings:
use_ldap = asbool(settings.get('pyvac.use_ldap'))
if use_ldap:
ldap = LdapCache()
users_teams = {}
for team, members in ldap.list_teams().iteritems():
for member in members:
users_teams.setdefault(member, []).append(team)
for req in requests:
user_teams = users_teams.get(req.user.dn, [])
matched = {}
# for all requests in conflict with current req
for req2 in Request.in_conflict(self.session, req):
# if we have some match between request teams
# and conflicting request teams
conflict_teams = users_teams.get(req2.user.dn, [])
common_set = set(conflict_teams) & set(user_teams)
if common_set:
for team in common_set:
if team not in matched:
matched[team] = []
matched[team].append(req2.summary)
req.conflict = matched
if req.conflict:
for team in req.conflict:
if req.id not in conflicts:
conflicts[req.id] = {}
conflicts[req.id][team] = ('\n'.join([team] +
req.conflict[team]))
else:
for req in requests:
req.conflict = [req2.summary for req2 in
Request.in_conflict_ou(self.session, req)]
if req.conflict:
conflicts[req.id] = '\n'.join(req.conflict)
req_list['requests'] = requests
req_list['conflicts'] = conflicts
# always add our requests
for req in Request.by_user(self.session, self.user):
if req not in req_list['requests']:
req_list['requests'].append(req)
return req_list