本文整理汇总了Python中pyvac.models.Request.by_user_future方法的典型用法代码示例。如果您正苦于以下问题:Python Request.by_user_future方法的具体用法?Python Request.by_user_future怎么用?Python Request.by_user_future使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvac.models.Request
的用法示例。
在下文中一共展示了Request.by_user_future方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from pyvac.models import Request [as 别名]
# 或者: from pyvac.models.Request import by_user_future [as 别名]
def render(self):
try:
form_date_from = self.request.params.get('date_from')
if ' - ' not in form_date_from:
msg = 'Invalid format for period.'
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
dates = self.request.params.get('date_from').split(' - ')
date_from = datetime.strptime(dates[0], '%d/%m/%Y')
date_to = datetime.strptime(dates[1], '%d/%m/%Y')
# retrieve holidays for user so we can remove them from selection
holidays = get_holiday(self.user, year=date_from.year,
use_datetime=True)
submitted = [d for d in daterange(date_from, date_to)
if d.isoweekday() not in [6, 7]
and d not in holidays]
days = float(len(submitted))
pool = None
days_diff = (date_to - date_from).days
if days_diff < 0:
msg = 'Invalid format for period.'
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
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))
# retrieve future requests for user so we can check overlap
futures = [d for req in
Request.by_user_future(self.session, self.user)
for d in daterange(req.date_from, req.date_to)]
intersect = set(futures) & set(submitted)
if intersect:
msg = 'Invalid period: days already requested.'
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')))
# check if vacation requires user role
if (vac_type.visibility
and self.user.role not in vac_type.visibility):
msg = 'You are not allowed to use type: %s' % vac_type.name
self.request.session.flash('error;%s' % msg)
return HTTPFound(location=route_url('home', self.request))
# 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':
pool = 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))
# check that we request vacations in the allowed year
if rtt_data is not None and (
date_from.year != rtt_data['year'] or
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
#.........这里部分代码省略.........