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


Python request.view_args方法代码示例

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


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

示例1: paginate

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def paginate(query, schema):
    page = request.args.get("page", DEFAULT_PAGE_NUMBER)
    per_page = request.args.get("page_size", DEFAULT_PAGE_SIZE)
    page_obj = query.paginate(page=page, per_page=per_page)
    next_ = url_for(
        request.endpoint,
        page=page_obj.next_num if page_obj.has_next else page_obj.page,
        per_page=per_page,
        **request.view_args
    )
    prev = url_for(
        request.endpoint,
        page=page_obj.prev_num if page_obj.has_prev else page_obj.page,
        per_page=per_page,
        **request.view_args
    )

    return {
        "total": page_obj.total,
        "pages": page_obj.pages,
        "next": next_,
        "prev": prev,
        "results": schema.dump(page_obj.items),
    } 
开发者ID:karec,项目名称:cookiecutter-flask-restful,代码行数:26,代码来源:pagination.py

示例2: lazy_raise_or_redirect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def lazy_raise_or_redirect():
    '''
    Raise exception lazily to ensure request.endpoint is set
    Also perform redirect if needed
    '''
    if not request.view_args:
        return
    for name, value in request.view_args.items():
        if isinstance(value, NotFound):
            request.routing_exception = value
            break
        elif isinstance(value, LazyRedirect):
            new_args = request.view_args
            new_args[name] = value.arg
            new_url = url_for(request.endpoint, **new_args)
            return redirect(new_url) 
开发者ID:opendatateam,项目名称:udata,代码行数:18,代码来源:routing.py

示例3: log_exception

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def log_exception(self, exc_info):
        self.logger.error("""
Path:                 %s
HTTP Method:          %s
Client IP Address:    %s
User Agent:           %s
User Platform:        %s
User Browser:         %s
User Browser Version: %s
GET args:             %s
view args:            %s
URL:                  %s
""" % (
            request.path,
            request.method,
            request.remote_addr,
            request.user_agent.string,
            request.user_agent.platform,
            request.user_agent.browser,
            request.user_agent.version,
            dict(request.args),
            request.view_args,
            request.url
        ), exc_info=exc_info) 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:26,代码来源:__init__.py

示例4: test_ipn_process

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_ipn_process(mocker, fail):
    rt = mocker.patch('indico_payment_paypal.controllers.register_transaction')
    post = mocker.patch('indico_payment_paypal.controllers.requests.post')
    mocker.patch('indico_payment_paypal.controllers.notify_amount_inconsistency')
    post.return_value.text = 'INVALID' if fail == 'verify' else 'VERIFIED'
    rh = RHPaypalIPN()
    rh._is_transaction_duplicated = lambda: fail == 'dup_txn'
    rh.event = MagicMock(id=1)
    rh.registration = MagicMock()
    rh.registration.getTotal.return_value = 10.00
    payment_status = {'fail': 'Failed', 'refund': 'Refunded', 'status': 'Foobar'}.get(fail, 'Completed')
    amount = '-10.00' if fail == 'negative' else '10.00'
    request.view_args = {'confId': rh.event.id}
    request.args = {'registrantId': '1'}
    request.form = {'payment_status': payment_status, 'txn_id': '12345', 'mc_gross': amount,
                    'mc_currency': 'EUR', 'business': 'foo@bar.com'}
    with PaypalPaymentPlugin.instance.plugin_context():
        rh._process()
        assert post.called
        assert rt.called == (fail is None) 
开发者ID:indico,项目名称:indico-plugins,代码行数:22,代码来源:controllers_test.py

示例5: _get_event_tracking_params

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def _get_event_tracking_params(self):
        site_id_events = PiwikPlugin.settings.get('site_id_events')
        if not self.settings.get('enabled_for_events') or not site_id_events:
            return {}
        params = {'site_id_events': site_id_events}
        if request.blueprint in ('event', 'events', 'contributions') and 'confId' in request.view_args:
            if not unicode(request.view_args['confId']).isdigit():
                return {}
            params['event_id'] = request.view_args['confId']
            contrib_id = request.view_args.get('contrib_id')
            if contrib_id is not None and unicode(contrib_id).isdigit():
                contribution = Contribution.find_first(event_id=params['event_id'], id=contrib_id)
                if contribution:
                    cid = (contribution.legacy_mapping.legacy_contribution_id if contribution.legacy_mapping
                           else contribution.id)
                    params['contrib_id'] = '{}t{}'.format(contribution.event_id, cid)
        return params 
开发者ID:indico,项目名称:indico-plugins,代码行数:19,代码来源:plugin.py

示例6: check_config_and_switch_read_only

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def check_config_and_switch_read_only():
    method = request.method
    view_args = request.view_args
    appid = view_args and view_args.get('application_name')

    response = api_response(
        message='Config and switch write inhibit',
        status="Forbidden")
    response.status_code = 403

    if method in READ_METHOD_SET:
        return
    if request.endpoint not in config_and_switch_readonly_endpoints:
        return
    if appid and appid in settings.CONFIG_AND_SWITCH_READONLY_BLACKLIST:
        return response
    if switch.is_switched_on(SWITCH_ENABLE_CONFIG_AND_SWITCH_WRITE, True):
        return
    if appid and appid in settings.CONFIG_AND_SWITCH_READONLY_WHITELIST:
        return
    return response 
开发者ID:huskar-org,项目名称:huskar,代码行数:23,代码来源:read_only.py

示例7: _test_permissions

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def _test_permissions(
    client,
    usr,
    permissions,
    will_succeed,
    kwargs=None,
):
    request.view_args.update({'service_id': 'foo'})
    if usr:
        client.login(usr)

    decorator = user_has_permissions(*permissions, **(kwargs or {}))
    decorated_index = decorator(index)

    if will_succeed:
        decorated_index()
    else:
        try:
            if (
                decorated_index().location != '/sign-in?next=%2F' or
                decorated_index().status_code != 302
            ):
                pytest.fail("Failed to throw a forbidden or unauthorised exception")
        except (Forbidden, Unauthorized):
            pass 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:27,代码来源:test_permissions.py

示例8: test_user_has_permissions_for_organisation

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_user_has_permissions_for_organisation(
    client,
    mocker,
):
    user = _user_with_permissions()
    user['organisations'] = ['org_1', 'org_2']
    mocker.patch('app.user_api_client.get_user', return_value=user)
    client.login(user)

    request.view_args = {'org_id': 'org_2'}

    @user_has_permissions()
    def index():
        pass

    index() 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:18,代码来源:test_permissions.py

示例9: test_platform_admin_can_see_orgs_they_dont_have

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_platform_admin_can_see_orgs_they_dont_have(
    client,
    platform_admin_user,
    mocker,
):
    platform_admin_user['organisations'] = []
    mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user)
    client.login(platform_admin_user)

    request.view_args = {'org_id': 'org_2'}

    @user_has_permissions()
    def index():
        pass

    index() 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:18,代码来源:test_permissions.py

示例10: test_cant_use_decorator_without_view_args

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_cant_use_decorator_without_view_args(
    client,
    platform_admin_user,
    mocker,
):
    mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user)
    client.login(platform_admin_user)

    request.view_args = {}

    @user_has_permissions()
    def index():
        pass

    with pytest.raises(NotImplementedError):
        index() 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:18,代码来源:test_permissions.py

示例11: test_user_doesnt_have_permissions_for_organisation

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_user_doesnt_have_permissions_for_organisation(
    client,
    mocker,
):
    user = _user_with_permissions()
    user['organisations'] = ['org_1', 'org_2']
    mocker.patch('app.user_api_client.get_user', return_value=user)
    client.login(user)

    request.view_args = {'org_id': 'org_3'}

    @user_has_permissions()
    def index():
        pass

    with pytest.raises(Forbidden):
        index() 
开发者ID:alphagov,项目名称:notifications-admin,代码行数:19,代码来源:test_permissions.py

示例12: i18n_alternate_links

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def i18n_alternate_links():
    """Render the <link rel="alternate" hreflang />

    if page is in a I18nBlueprint
    """
    if (not request.endpoint or
            not current_app.url_map.is_endpoint_expecting(request.endpoint,
                                                          'lang_code')):
        return Markup('')

    try:
        LINK_PATTERN = (
            '<link rel="alternate" href="{url}" hreflang="{lang}" />')
        links = []
        current_lang = get_current_locale().language

        params = {}
        if request.args:
            params.update(request.args)
        if request.view_args:
            params.update(request.view_args)

        for lang in current_app.config['LANGUAGES']:
            if lang != current_lang:
                url = url_for(request.endpoint, lang_code=lang, **params)
                links.append(LINK_PATTERN.format(url=url, lang=lang))
        return Markup(''.join(links))
    except Exception:
        # Never fails
        return Markup('') 
开发者ID:opendatateam,项目名称:udata,代码行数:32,代码来源:helpers.py

示例13: output

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def output(self, key, obj, **kwargs):
        if not getattr(obj, 'has_next', None):
            return None
        args = multi_to_dict(request.args)
        args.update(request.view_args)
        args['page'] = obj.page + 1
        return url_for(request.endpoint, _external=True, **args) 
开发者ID:opendatateam,项目名称:udata,代码行数:9,代码来源:fields.py

示例14: test_gauge

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def test_gauge(self):
        metrics = self.metrics()

        @self.app.route('/test/1')
        @metrics.gauge('gauge_1', 'Gauge 1')
        def test1():
            self.assertMetric('gauge_1', '1.0')

            return 'OK'

        self.client.get('/test/1')

        self.assertMetric('gauge_1', '0.0')

        @self.app.route('/test/<int:a>')
        @metrics.gauge('gauge_2', 'Gauge 2', labels={
            'uri': lambda: request.path,
            'a_value': lambda: request.view_args['a']
        })
        def test2(a):
            self.assertMetric(
                'gauge_2', '1.0',
                ('uri', '/test/2'), ('a_value', 2)
            )

            return 'OK: %d' % a

        self.client.get('/test/2')

        self.assertMetric(
            'gauge_2', '0.0',
            ('uri', '/test/2'), ('a_value', 2)
        ) 
开发者ID:rycus86,项目名称:prometheus_flask_exporter,代码行数:35,代码来源:test_metrics.py

示例15: _process_args

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import view_args [as 别名]
def _process_args(self):
        if 'confId' in request.view_args:
            self.obj = Event.get_or_404(request.view_args['confId'], is_deleted=False)
            self.obj_type = 'event'
        elif 'category_id' in request.view_args:
            self.obj = Category.get_or_404(request.view_args['category_id'], is_deleted=False)
            self.obj_type = 'category' if not self.obj.is_root else None
        else:
            self.obj = Category.get_root()
            self.obj_type = None 
开发者ID:indico,项目名称:indico-plugins,代码行数:12,代码来源:controllers.py


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