本文整理汇总了Python中pyvac.models.Request类的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
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_post_send_exception_reason_length_ko
def test_post_send_exception_reason_length_ko(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
with freeze_time('2015-10-01',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
request = self.create_request({
'days': 1,
'date_from': '12/11/2015 - 12/11/2015',
'type': '6',
'breakdown': 'FULL',
'exception_text': "I need to see Star Wars, I'm a huge fan"
"please, please, please, please, please, "
"please, please, please, please, please, "
"please, please, please, please, please, "
"please, please, please, please, please, "
"please, please, please, please, please, "
"please, please, please, please, please, ",
})
view = Send(request)()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req)
expected = [u'error;Exceptionnel reason must not exceed 140 '
'characters']
self.assertEqual(request.session.pop_flash(), expected)
示例3: test_in_conflict_manager
def test_in_conflict_manager(self):
from pyvac.models import Request
req = Request.by_id(self.session, 1)
self.assertIsInstance(req, Request)
nb_conflicts = Request.in_conflict_manager(self.session, req,
count=True)
self.assertEqual(nb_conflicts, 1)
示例4: test_post_send_rtt_usage_empty_ok
def test_post_send_rtt_usage_empty_ok(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request, User
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
def mock_get_rtt_usage(self, session):
""" Get rrt usage for a user """
return
orig_get_rtt_usage = User.get_rtt_usage
User.get_rtt_usage = mock_get_rtt_usage
user = User.by_login(self.session, u'janedoe')
rtt_data = user.get_rtt_usage(self.session)
self.assertIsNone(rtt_data)
view = Send(self.create_request({
'days': 1,
'date_from': '05/05/2015 - 05/05/2015',
'type': '2',
'breakdown': 'AM',
}))()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req + 1)
User.get_rtt_usage = orig_get_rtt_usage
示例5: test_post_send_rtt_usage_not_enough_ko
def test_post_send_rtt_usage_not_enough_ko(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request, User
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
def mock_get_rtt_usage(self, session):
""" Get rrt usage for a user """
return {'allowed': 10, 'left': 0.5, 'state': 'error',
'taken': 9.5, 'year': 2014}
orig_get_rtt_usage = User.get_rtt_usage
User.get_rtt_usage = mock_get_rtt_usage
user = User.by_login(self.session, u'janedoe')
rtt_data = user.get_rtt_usage(self.session)
self.assertTrue(rtt_data)
request = self.create_request({'days': 1,
'date_from': '05/05/2015 - 05/05/2015',
'type': '2',
'breakdown': 'FULL',
})
view = Send(request)()
self.assertIsRedirect(view)
# no new requests were made
self.assertEqual(Request.find(self.session, count=True), total_req)
expected = ['error;You only have 0.5 RTT to use.']
self.assertEqual(request.session.pop_flash(), expected)
User.get_rtt_usage = orig_get_rtt_usage
示例6: test_post_send_recovery_ok
def test_post_send_recovery_ok(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
msg = u"I need to see Star Wars, because I'm a really huge fan !!!"
with freeze_time('2015-10-01',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
request = self.create_request({
'days': 1,
'date_from': '12/11/2015 - 12/11/2015',
'type': '4',
'breakdown': 'FULL',
'exception_text': msg,
})
view = Send(request)()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req + 1)
last_req = Request.find(self.session)[-1]
self.assertEqual(last_req.type, u'Récupération')
self.assertEqual(last_req.message, msg)
self.session.delete(last_req)
示例7: test_post_send_wrong_date_ko
def test_post_send_wrong_date_ko(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
view = Send(self.create_request({'date_from': 'foo'}))()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req)
示例8: replay
def replay(settings):
with open(settings["pyvac.celery.yaml"]) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
caldav_url = Conf.get("caldav").get("url")
# XXX Register the database
create_engine(settings, scoped=True)
session = DBSession()
calendar = get_calendar(caldav_url)
requests = Request.find(session, where=(Request.status == "APPROVED_ADMIN",), order_by=Request.user_id)
print "total requests", len(requests)
print ""
req_to_add = []
# for each requests
for req in requests:
print "-" * 10
print req.id, req.summarycal, req.date_from, req.date_to
# check if entry in caldav exists
results = calendar.date_search(req.date_from, req.date_to)
if not results:
# need to add missing entry in caldav
print "need to insert request"
req_to_add.append(req.id)
else:
summaries = []
for event in results:
try:
parse_event(event)
except Exception:
continue
event.load()
# XXX: if needed to delete entries
# uid = event.instance.vevent.uid.value
# ics = '%s/%s.ics' % (caldav_url, uid)
# print delFromCal(caldav_url, ics)
summary = event.instance.vevent.summary.value
summaries.append(summary)
if req.summarycal not in summaries:
print "need to insert request"
req_to_add.append(req.id)
for req_id in set(req_to_add):
req = Request.by_id(session, req_id)
print "processing", req.id, req.summarycal, req.date_from, req.date_to
ics_url = addToCal(caldav_url, req.date_from, req.date_to, req.summarycal)
# save ics url in request
req.ics_url = ics_url
session.add(req)
session.flush()
transaction.commit()
示例9: test_by_user_outdated
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)
示例10: render
def render(self):
if not self.user:
return self.redirect()
_ = self.request.translate
self.user.rtt = self.user.get_rtt_usage(self.session)
holidays = get_holiday(self.user)
ret_dict = {'types': [], 'holidays': holidays, 'sudo_users': [],
'futures_pending': [], 'futures_approved': []}
vacation_types = VacationType.by_country(self.session,
self.user.country)
for vac in vacation_types:
if vac.visibility and self.user.role not in vac.visibility:
continue
ret_dict['types'].append({'name': _(vac.name), 'id': vac.id})
if self.user.is_admin:
ret_dict['sudo_users'] = User.for_admin(self.session, self.user)
futures_pending = [timestamp
for req in
Request.by_user_future_pending(self.session,
self.user)
for timestamp in req.timestamps]
ret_dict['futures_pending'] = futures_pending
futures_approved = [timestamp
for req in
Request.by_user_future_approved(self.session,
self.user)
for timestamp in req.timestamps]
ret_dict['futures_approved'] = futures_approved
exception_info_tooltip = """\
This type is for events which are not covered by other types: \
wedding, funeral, etc.
Providing a reason for this request is mandatory.
"""
ret_dict['exception_info_tooltip'] = _(exception_info_tooltip)
if self.request.matched_route:
matched_route = self.request.matched_route.name
ret_dict.update({
'matched_route': matched_route,
'csrf_token': self.request.session.get_csrf_token()})
return ret_dict
ret_dict.update({'csrf_token': self.request.session.get_csrf_token()})
return ret_dict
示例11: test_post_send_ok
def test_post_send_ok(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Send
total_req = Request.find(self.session, count=True)
view = Send(self.create_request({'days': 4,
'date_from': '05/05/2014 - 10/05/2014',
'type': 'CP',
}))()
self.assertIsRedirect(view)
self.assertEqual(Request.find(self.session, count=True), total_req + 1)
示例12: test_by_user_outdated
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)
示例13: run
def run(self, *args, **kwargs):
self.log = log
# init database connection
session = DBSession()
statuses = ['PENDING',
'ACCEPTED_MANAGER',
'DENIED',
'APPROVED_ADMIN',
'CANCELED',
'ERROR']
for status in statuses:
requests = Request.by_status(session, status)
self.log.info('number of requests for %s: %d' %
(status, len(requests)))
req_accepted_notified = Request.by_status(session, 'ACCEPTED_MANAGER',
notified=True)
self.log.info('number of ACCEPTED_NOTIFIED requests: %d' %
len(req_accepted_notified))
# req_pending_notified = Request.by_status(session, 'PENDING',
# notified=True)
# self.log.info('number of PENDING_NOTIFIED requests: %d' %
# len(req_pending_notified))
req_list = []
req_list.extend(req_accepted_notified)
# req_list.extend(req_pending_notified)
for req in req_list:
self.log.info('selecting task for req type %r' % req.status)
check_status = req.status
if req.status == 'ACCEPTED_MANAGER' and req.notified:
check_status = 'ACCEPTED_NOTIFIED'
# if req.status == 'PENDING' and req.notified:
# check_status = 'PENDING_NOTIFIED'
req_task = self.worker_tasks[check_status]
self.log.info('task selected %r' % req_task.name)
data = {
'req_id': req.id,
}
async_result = subtask(req_task).delay(data=data)
self.log.info('task scheduled %r' % async_result)
return True
示例14: get_conflict_by_teams
def get_conflict_by_teams(self, requests, users_teams):
""" Returns requests conflicts by teams """
conflicts = {}
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]))
return conflicts
示例15: test_by_status
def test_by_status(self):
from pyvac.models import Request
requests = Request.by_status(self.session, u'PENDING')
self.assertEqual(len(requests), 4)
# take the first
request = requests[0]
self.assertIsInstance(request, Request)