当前位置: 首页>>代码示例>>Python>>正文


Python User.by_id方法代码示例

本文整理汇总了Python中pyvac.models.User.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.by_id方法的具体用法?Python User.by_id怎么用?Python User.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvac.models.User的用法示例。


在下文中一共展示了User.by_id方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
    def process(self, data):
        """ denied by last_action_user_id
        send mail to user
        """
        req = Request.by_id(self.session, data['req_id'])

        # retrieve user who performed last action
        action_user = User.by_id(self.session, req.last_action_user_id)
        # send mail to user
        src = action_user.email
        dst = req.user.email
        content = """You request has been refused for the following reason: %s
Request details: %s""" % (req.reason, req.summarymail)
        try:
            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()
开发者ID:baloo,项目名称:pyvac,代码行数:27,代码来源:worker.py

示例2: render

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
    def render(self):
        user = User.by_id(self.session,
                          int(self.request.matchdict['user_id']))

        if self.user.has_no_role:
            # can only see own requests
            if user.id != self.user.id:
                return HTTPFound(location=route_url('list_request',
                                                    self.request))

        if self.user.is_manager:
            # can only see own requests and managed user requests
            if ((user.id != self.user.id)
                    and (user.manager_id != self.user.id)):
                return HTTPFound(location=route_url('list_request',
                                                    self.request))

        today = datetime.now()
        year = int(self.request.params.get('year', today.year))

        start = datetime(2014, 5, 1)
        years = [item for item in reversed(range(start.year, today.year + 1))]

        pool_history = User.get_rtt_history(self.session, user, year)

        return {'user': user, 'year': year, 'years': years,
                'pool_history': pool_history}
开发者ID:doyousoft,项目名称:pyvac,代码行数:29,代码来源:request.py

示例3: test_post_delete_ok

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
 def test_post_delete_ok(self):
     from pyvac.views.account import Delete
     from pyvac.models import User
     view = Delete(self.create_request({'form.submitted': '1',
                                        },
                                       matchdict={'user_id': self.account_id
                                                  },))()
     self.assertIsRedirect(view)
     account = User.by_id(self.session, self.account_id)
     self.assertIsNone(account)
     self.account_todelete = []
开发者ID:doyousoft,项目名称:pyvac,代码行数:13,代码来源:test_account.py

示例4: test_post_edit_ok

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
 def test_post_edit_ok(self):
     from pyvac.views.account import Edit
     from pyvac.models import User
     view = Edit(self.create_request({'form.submitted': '1',
                                      'user.login': u'dummy_edited',
                                      'user.firstname': u'',
                                      'user.lastname': u'',
                                      'user.email': u'[email protected]',
                                      'groups': [u'1']
                                      },
                                     matchdict={'user_id': self.account_id
                                                }))()
     self.assertIsRedirect(view)
     self.session.flush()
     user = User.by_id(self.session, self.account_id)
     self.assertEqual(user.login, u'dummy_edited')
     self.assertEqual([g.id for g in user.groups], [1])
开发者ID:doyousoft,项目名称:pyvac,代码行数:19,代码来源:test_account.py

示例5: render

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
    def render(self):
        if not self.user.is_sudoer(self.session):
            log.info("user '%s' tried to access sudo but is not authorized" % self.user.login)
            return HTTPFound(location=route_url("home", self.request))

        req = self.request
        if req.method == "POST" and "continue" in req.params:
            headers = None
            target_id = int(req.params.get("sudo", self.user.id))
            if target_id != self.user.id:
                target = User.by_id(self.session, target_id)
                if not target:
                    errors = ["Cannot find user with id %d" % target_id]
                    self.request.session.flash("error;%s" % ",".join(errors))

                log.info("user '%s' will sudo to user '%s'" % (self.user.login, target.login))
                headers = remember(self.request, target.login)
            return HTTPFound(location=route_url("home", self.request), headers=headers)

        return {"user": self.user}
开发者ID:doyousoft,项目名称:pyvac,代码行数:22,代码来源:credentials.py

示例6: tearDown

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [as 别名]
 def tearDown(self):
     from pyvac.models import User
     for id in self.account_todelete:
         u = User.by_id(self.session, id)
         self.session.delete(u)
     super(AccountTestCase, self).tearDown()
开发者ID:doyousoft,项目名称:pyvac,代码行数:8,代码来源:test_account.py

示例7: render

# 需要导入模块: from pyvac.models import User [as 别名]
# 或者: from pyvac.models.User import by_id [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')

            days = float(len([d for d in daterange(date_from, date_to)
                              if d.isoweekday() not in [6, 7]]))

            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))

            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},
#.........这里部分代码省略.........
开发者ID:baloo,项目名称:pyvac,代码行数:103,代码来源:request.py


注:本文中的pyvac.models.User.by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。