當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。