本文整理汇总了Python中pyvac.models.Request.add_to_cal方法的典型用法代码示例。如果您正苦于以下问题:Python Request.add_to_cal方法的具体用法?Python Request.add_to_cal怎么用?Python Request.add_to_cal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.Request
的用法示例。
在下文中一共展示了Request.add_to_cal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import add_to_cal [as 别名]
#.........这里部分代码省略.........
date_to.year != rtt_data['year']):
msg = ('RTT can only be used for year %d.' %
rtt_data['year'])
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
message = None
# check Exceptionnel mandatory field
if vac_type.name == u'Exceptionnel':
message = self.request.params.get('exception_text')
message = message.strip() if message else message
if not message:
msg = ('You must provide a reason for %s requests' %
vac_type.name)
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# check size
if len(message) > 140:
msg = ('%s reason must not exceed 140 characters' %
vac_type.name)
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# check Récupération reason field
if vac_type.name == u'Récupération':
message = self.request.params.get('exception_text')
message = message.strip() if message else message
# check size
if message and len(message) > 140:
msg = ('%s reason must not exceed 140 characters' %
vac_type.name)
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# create the request
# default values
target_status = u'PENDING'
target_user = self.user
target_notified = False
sudo_use = False
if self.user.is_admin:
sudo_user_id = int(self.request.params.get('sudo_user'))
if sudo_user_id != -1:
user = User.by_id(self.session, sudo_user_id)
if user:
sudo_use = True
target_user = user
target_status = u'APPROVED_ADMIN'
target_notified = True
# save pool status when making the request
if pool:
pool_status = json.dumps(pool)
else:
pool_status = json.dumps({})
request = Request(date_from=date_from,
date_to=date_to,
days=days,
vacation_type=vac_type,
status=target_status,
user=target_user,
notified=target_notified,
label=label,
message=message,
pool_status=pool_status,
)
self.session.add(request)
self.session.flush()
if request and not sudo_use:
msg = 'Request sent to your manager.'
self.request.session.flash('info;%s' % msg)
# call celery task directly, do not wait for polling
from celery.registry import tasks
from celery.task import subtask
req_task = tasks['worker_pending']
data = {'req_id': request.id}
subtask(req_task).apply_async(kwargs={'data': data},
countdown=5)
log.info('scheduling task worker_pending for %s' % data)
if request and sudo_use:
settings = self.request.registry.settings
if 'pyvac.celery.yaml' in settings:
with open(settings['pyvac.celery.yaml']) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
caldav_url = Conf.get('caldav').get('url')
request.add_to_cal(caldav_url)
msg = 'Request added to calendar and DB.'
self.request.session.flash('info;%s' % msg)
except Exception as exc:
log.error(exc)
msg = ('An error has occured while processing this request: %r'
% exc)
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
示例2: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import add_to_cal [as 别名]
#.........这里部分代码省略.........
if (date_to == date_from) and days > 1:
# same day, asking only for one or less day duration
msg = 'Invalid value for days.'
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
if days <= 0:
msg = 'Invalid value for days.'
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
vac_type = VacationType.by_id(self.session,
int(self.request.params.get('type')))
# label field is used when requesting half day
label = u''
breakdown = self.request.params.get('breakdown')
if breakdown != 'FULL':
# handle half day
if (days > 1):
msg = ('AM/PM option must be used only when requesting a '
'single day.')
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
else:
days = 0.5
label = unicode(breakdown)
# check RTT usage
if vac_type.name == u'RTT':
rtt_data = self.user.get_rtt_usage(self.session)
if rtt_data is not None and rtt_data['left'] <= 0:
msg = 'No RTT left to take.'
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# check that we have enough RTT to take
if rtt_data is not None and days > rtt_data['left']:
msg = 'You only have %s RTT to use.' % rtt_data['left']
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# create the request
# default values
target_status = u'PENDING'
target_user = self.user
target_notified = False
sudo_use = False
if self.user.is_admin:
sudo_user_id = int(self.request.params.get('sudo_user'))
if sudo_user_id != -1:
user = User.by_id(self.session, sudo_user_id)
if user:
sudo_use = True
target_user = user
target_status = u'APPROVED_ADMIN'
target_notified = True
request = Request(date_from=date_from,
date_to=date_to,
days=days,
vacation_type=vac_type,
status=target_status,
user=target_user,
notified=target_notified,
label=label,
)
self.session.add(request)
self.session.flush()
if request and not sudo_use:
msg = 'Request sent to your manager.'
self.request.session.flash('info;%s' % msg)
# call celery task directly, do not wait for polling
from celery.registry import tasks
from celery.task import subtask
req_task = tasks['worker_pending']
data = {'req_id': request.id}
subtask(req_task).apply_async(kwargs={'data': data},
countdown=5)
log.info('scheduling task worker_pending for %s' % data)
if request and sudo_use:
settings = self.request.registry.settings
if 'pyvac.celery.yaml' in settings:
with open(settings['pyvac.celery.yaml']) as fdesc:
Conf = yaml.load(fdesc, YAMLLoader)
caldav_url = Conf.get('caldav').get('url')
request.add_to_cal(caldav_url)
msg = 'Request added to calendar and DB.'
self.request.session.flash('info;%s' % msg)
except Exception as exc:
log.error(exc)
msg = ('An error has occured while processing this request: %r'
% exc)
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))