• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Request类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:grigouze,项目名称:pyvac,代码行数:25,代码来源:request.py


示例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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:30,代码来源:test_request.py


示例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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:7,代码来源:test_models.py


示例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
开发者ID:doyousoft,项目名称:pyvac,代码行数:26,代码来源:test_request.py


示例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
开发者ID:doyousoft,项目名称:pyvac,代码行数:30,代码来源:test_request.py


示例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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:26,代码来源:test_request.py


示例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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:9,代码来源:test_request.py


示例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()
开发者ID:doyousoft,项目名称:pyvac,代码行数:55,代码来源:replay.py


示例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)
开发者ID:baloo,项目名称:pyvac,代码行数:11,代码来源:test_models.py


示例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
开发者ID:doyousoft,项目名称:pyvac,代码行数:53,代码来源:__init__.py


示例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)
开发者ID:grigouze,项目名称:pyvac,代码行数:12,代码来源:test_request.py


示例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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:13,代码来源:test_models.py


示例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
开发者ID:doyousoft,项目名称:pyvac,代码行数:50,代码来源:poller.py


示例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
开发者ID:doyousoft,项目名称:pyvac,代码行数:27,代码来源:request.py


示例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)
开发者ID:soulshake,项目名称:pyvac,代码行数:7,代码来源:test_models.py


示例16: render

    def render(self):
        from datetime import datetime
        today = datetime.now()
        end_date = datetime(today.year, 10, 31)

        previsions = Request.get_previsions(self.session, end_date)

        users_per_id = dict([(user.id, user)
                             for user in User.find(self.session)])

        settings = self.request.registry.settings
        use_ldap = False
        if 'pyvac.use_ldap' in settings:
            use_ldap = asbool(settings.get('pyvac.use_ldap'))

        user_attr = {}
        users_teams = {}
        if use_ldap:
            # synchronise user groups/roles
            User.sync_ldap_info(self.session)
            ldap = LdapCache()
            user_attr = ldap.get_users_units()
            users_teams = {}
            for team, members in ldap.list_teams().iteritems():
                for member in members:
                    users_teams.setdefault(member, []).append(team)

        return {'users_per_id': users_per_id,
                'use_ldap': use_ldap,
                'ldap_info': user_attr,
                'users_teams': users_teams,
                'previsions': previsions,
                'today': today,
                'end_date': end_date,
                }
开发者ID:doyousoft,项目名称:pyvac,代码行数:35,代码来源:request.py


示例17: process

    def process(self, data):
        """ submitted by user
        send mail to manager
        """
        req = Request.by_id(self.session, data['req_id'])
        # send mail to manager
        src = req.user.email
        dst = req.user.manager_mail
        if 'reminder' in data:
            content = """A request from %s is still waiting your approval
Request details: %s""" % (req.user.name, req.summarymail)
        else:
            content = """New request from %s
Request details: %s""" % (req.user.name, 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,代码行数:25,代码来源:worker.py


示例18: test_summarycsv_message

 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)
开发者ID:doyousoft,项目名称:pyvac,代码行数:7,代码来源:test_models.py


示例19: test_all_for_admin

 def test_all_for_admin(self):
     from pyvac.models import Request
     with freeze_time('2014-12-25',
                      ignore=['celery', 'psycopg2', 'sqlalchemy',
                              'icalendar']):
         nb_requests = Request.all_for_admin(self.session, count=True)
     self.assertEqual(nb_requests, 19)
开发者ID:doyousoft,项目名称:pyvac,代码行数:7,代码来源:test_models.py


示例20: test_get_by_month

 def test_get_by_month(self):
     from pyvac.models import Request
     month = 8
     year = 2011
     country = u'fr'
     requests = Request.get_by_month(self.session, country, month, year)
     self.assertEqual(len(requests), 1)
开发者ID:doyousoft,项目名称:pyvac,代码行数:7,代码来源:test_models.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.User类代码示例发布时间:2022-05-27
下一篇:
Python legislation.Bill类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap