本文整理汇总了Python中pyvac.models.Request.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Request.by_id方法的具体用法?Python Request.by_id怎么用?Python Request.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.Request
的用法示例。
在下文中一共展示了Request.by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_summarycsv
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_summarycsv(self):
from pyvac.models import Request
req = Request.by_id(self.session, 1)
self.assertIsInstance(req, Request)
msg = u"Doe,John,10/04/2015,14/04/2015,5.0,CP,"
self.assertEqual(req.summarycsv, msg)
示例2: test_in_conflict_manager
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
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)
示例3: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def render(self):
req_id = self.request.params.get('request_id')
req = Request.by_id(self.session, req_id)
if not req:
return ''
# check if request have already been consumed
if not self.user.is_admin:
today = datetime.now()
if req.date_from <= today:
log.error('User %s tried to CANCEL consumed request %d.' %
(self.user.login, req.id))
return req.status
# delete from calendar
if req.status == 'APPROVED_ADMIN' and req.ics_url:
settings = self.request.registry.settings
with open(settings['pyvac.celery.yaml']) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
caldav_url = Conf.get('caldav').get('url')
delFromCal(caldav_url, req.ics_url)
req.update_status('CANCELED')
# save who performed this action
req.last_action_user_id = self.user.id
self.session.flush()
return req.status
示例4: test_summarycsv_label
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_summarycsv_label(self):
from pyvac.models import Request
req = Request.by_id(self.session, 6)
self.assertIsInstance(req, Request)
msg = u"Doe,John,24/08/2011,24/08/2011,0.5,RTT,AM"
self.assertEqual(req.summarycsv, msg)
示例5: process
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def process(self, data):
""" accepted by manager
send mail to user
send mail to HR
"""
req = Request.by_id(self.session, data['req_id'])
# send mail to user
src = req.user.manager_mail
dst = req.user.email
content = """Your request has been accepted by %s. Waiting for HR validation.
Request details: %s""" % (req.user.manager_name, req.summarymail)
try:
self.send_mail(sender=src, target=dst, request=req,
content=content)
# send mail to HR
admin = req.user.get_admin(self.session)
dst = self.get_admin_mail(admin)
content = """Manager %s has accepted a new request. Waiting for your validation.
Request details: %s""" % (req.user.manager_name, req.summarymail)
self.send_mail(sender=src, target=dst, request=req,
content=content)
# update request status after sending email
req.notified = True
except Exception as err:
self.log.exception('Error while sending mail')
req.flag_error(str(err))
self.session.flush()
transaction.commit()
示例6: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def render(self):
req_id = self.request.params.get('request_id')
req = Request.by_id(self.session, req_id)
if not req:
return ''
data = {'req_id': req.id}
if self.user.is_admin:
req.update_status('APPROVED_ADMIN')
# save who performed this action
req.last_action_user_id = self.user.id
task_name = 'worker_approved'
settings = self.request.registry.settings
with open(settings['pyvac.celery.yaml']) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
data['caldav.url'] = Conf.get('caldav').get('url')
else:
req.update_status('ACCEPTED_MANAGER')
# save who performed this action
req.last_action_user_id = self.user.id
task_name = 'worker_accepted'
self.session.flush()
# call celery task directly, do not wait for polling
from celery.registry import tasks
from celery.task import subtask
req_task = tasks[task_name]
subtask(req_task).delay(data=data)
return req.status
示例7: test_summarycsv_message
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_summarycsv_message(self):
from pyvac.models import Request
req = Request.by_id(self.session, 14)
self.assertIsInstance(req, Request)
msg = (u"Doe,Jane,13/06/2016,13/06/2016,1.0,Exceptionnel,,"
"I need to see Star Wars, I'm a huge fan")
self.assertEqual(req.summarycsv, msg)
示例8: process
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def process(self, data):
""" approved by HR
send mail to user
send mail to manager
"""
req = Request.by_id(self.session, data['req_id'])
admin = req.user.get_admin(self.session)
# send mail to user
src = self.get_admin_mail(admin)
dst = req.user.email
if 'autoaccept' in data:
content = """Your request was automatically approved, it has been added to calendar.
Request details: %s""" % req.summarymail
else:
content = """HR has accepted your request, it has been added to calendar.
Request details: %s""" % req.summarymail
try:
self.send_mail(sender=src, target=dst, request=req, content=content)
# send mail to manager
src = self.get_admin_mail(admin)
dst = req.user.manager_mail
if 'autoaccept' in data:
content = """A request you accepted was automatically approved, it has been added to calendar.
Request details: %s""" % req.summarymail
else:
content = """HR has approved a request you accepted, it has been added to calendar.
Request details: %s""" % req.summarymail
self.send_mail(sender=src, target=dst, request=req, content=content)
# update request status after sending email
req.notified = True
except Exception as err:
log.exception('Error while sending mail')
req.flag_error(str(err))
try:
if 'caldav.url' in data:
caldav_url = data['caldav.url']
else:
conf_file = sys.argv[1]
with open(conf_file) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
caldav_url = Conf.get('caldav').get('url')
# add new entry in caldav
addToCal(caldav_url,
req.date_from,
req.date_to,
req.summarycal)
except Exception as err:
log.exception('Error while adding to calendar')
req.flag_error(str(err))
self.session.flush()
transaction.commit()
示例9: replay
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
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()
示例10: test_by_user_outdated
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [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)
示例11: test_set_status_cancel_ko_consumed_during
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_set_status_cancel_ko_consumed_during(self):
self.config.testing_securitypolicy(userid=u'manager3',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Cancel
req_id = 5
req = Request.by_id(self.session, req_id)
self.assertEqual(req.status, u'APPROVED_ADMIN')
with freeze_time('2015-04-25',
ignore=['celery', 'psycopg2', 'sqlalchemy',
'icalendar']):
status = Cancel(self.create_request({'request_id': req_id}))()
self.assertEqual(status, u'APPROVED_ADMIN')
示例12: test_by_user_outdated
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [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)
示例13: test_set_status_accept_admin_ok
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_set_status_accept_admin_ok(self):
self.config.testing_securitypolicy(userid=u'admin',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Accept
req_id = 1
req = Request.by_id(self.session, req_id)
orig_status = req.status
status = Accept(self.create_request({'request_id': req_id}))()
self.assertEqual(status, u'APPROVED_ADMIN')
self.session.commit()
self.assertEqual(req.status, u'APPROVED_ADMIN')
self.assertEqual(req.notified, False)
req.update_status(orig_status)
示例14: test_set_status_refuse_manager_ok
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_set_status_refuse_manager_ok(self):
self.config.testing_securitypolicy(userid=u'manager1',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Refuse
req_id = 1
req = Request.by_id(self.session, req_id)
orig_status = req.status
status = Refuse(self.create_request({'request_id': req_id}))()
self.assertEqual(status, u'DENIED')
self.session.commit()
self.assertEqual(req.status, u'DENIED')
self.assertEqual(req.notified, False)
req.update_status(orig_status)
示例15: test_set_status_cancel_ok
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_id [as 别名]
def test_set_status_cancel_ok(self):
self.config.testing_securitypolicy(userid=u'janedoe',
permissive=True)
from pyvac.models import Request
from pyvac.views.request import Cancel
req_id = 1
req = Request.by_id(self.session, req_id)
orig_status = req.status
status = Cancel(self.create_request({'request_id': req_id}))()
self.assertEqual(status, u'CANCELED')
self.session.commit()
self.assertEqual(req.status, u'CANCELED')
self.assertEqual(req.notified, False)
req.update_status(orig_status)