本文整理汇总了Python中pyvac.models.Request.by_user方法的典型用法代码示例。如果您正苦于以下问题:Python Request.by_user方法的具体用法?Python Request.by_user怎么用?Python Request.by_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.Request
的用法示例。
在下文中一共展示了Request.by_user方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def render(self):
req_list = {'requests': [], 'conflicts': {}}
requests = []
if self.user.is_admin:
requests = Request.all_for_admin(self.session)
elif self.user.is_super:
requests = Request.by_manager(self.session, self.user)
if requests:
conflicts = {}
for req in requests:
req.conflict = [req2.summary for req2 in
Request.in_conflict(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
示例2: test_by_user_outdated
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def test_by_user_outdated(self):
from pyvac.models import User, Request
user1 = User.by_login(self.session, u"jdoe")
requests = Request.by_user(self.session, user1)
self.assertEqual(len(requests), 5)
outdated = Request.by_id(self.session, 7)
self.assertIsInstance(outdated, Request)
self.assertEqual(outdated.user, user1)
self.assertFalse(outdated in requests)
示例3: delete
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def delete(self, account):
# cancel all associated requests for this user
requests = Request.by_user(self.session, account)
for req in requests:
req.update_status('CANCELED')
super(Delete, self).delete(account)
if account.ldap_user:
# delete in ldap
ldap = LdapCache()
ldap.delete_user(account.dn)
示例4: test_by_user_outdated
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def test_by_user_outdated(self):
from pyvac.models import User, Request
user1 = User.by_login(self.session, u'jdoe')
with freeze_time('2015-08-01',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
requests = Request.by_user(self.session, user1)
self.assertEqual(len(requests), 8)
outdated = Request.by_id(self.session, 7)
self.assertIsInstance(outdated, Request)
self.assertEqual(outdated.user, user1)
self.assertFalse(outdated in requests)
示例5: delete
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def delete(self, account):
# cancel all associated requests for this user
requests = Request.by_user(self.session, account)
for req in requests:
req.update_status('CANCELED')
super(Delete, self).delete(account)
if account.ldap_user:
# delete in ldap
ldap = LdapCache()
try:
ldap.delete_user(account.dn)
except IndexError:
log.info('User %s seems already deleted in ldap' % account.dn)
示例6: test_by_user
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def test_by_user(self):
from pyvac.models import User, Request
user1 = User.by_login(self.session, u'jdoe')
requests = Request.by_user(self.session, user1)
self.assertEqual(len(requests), 2)
# take the first
request = requests[0]
self.assertIsInstance(request, Request)
self.assertEqual(request.days, 5)
self.assertEqual(request.type, u'CP')
self.assertEqual(request.status, u'PENDING')
self.assertEqual(request.notified, False)
self.assertEqual(request.date_from, datetime(2014, 4, 10, 0, 0))
self.assertEqual(request.date_to, datetime(2014, 4, 14, 0, 0))
示例7: test_by_user
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [as 别名]
def test_by_user(self):
from pyvac.models import User, Request
user1 = User.by_login(self.session, u'jdoe')
with freeze_time('2015-08-01',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
requests = Request.by_user(self.session, user1)
self.assertEqual(len(requests), 8)
# take the first
request = requests[-1]
self.assertIsInstance(request, Request)
self.assertEqual(request.days, 5)
self.assertEqual(request.type, u'CP')
self.assertEqual(request.status, u'PENDING')
self.assertEqual(request.notified, False)
self.assertEqual(request.date_from, datetime(2015, 4, 10, 0, 0))
self.assertEqual(request.date_to, datetime(2015, 4, 14, 0, 0))
示例8: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [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
示例9: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user [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