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

Python view.render_view_to_response函数代码示例

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

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



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

示例1: test_delete_user_action

    def test_delete_user_action(self, users, groups):
        group = groups['group99']
        group.model.add('uid99')
        group.model()

        user = users['uid99']

        request = self.layer.new_request(type='json')
        with self.layer.authenticated('viewer'):
            self.expectError(
                HTTPForbidden,
                render_view_to_response,
                user,
                request,
                name='delete_item'
            )

        with self.layer.authenticated('admin'):
            res = render_view_to_response(user, request, name='delete_item')
        self.assertEqual(json.loads(res.text), {
            'message': "Deleted user 'uid99' from database.",
            'success': True
        })

        with self.layer.authenticated('admin'):
            res = render_view_to_response(user, request, name='delete_item')
        self.assertEqual(json.loads(res.text), {
            'message': "u'uid99'" if compat.IS_PY2 else "'uid99'",
            'success': False
        })

        self.assertEqual(group.model.users, [])
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:32,代码来源:test_browser_actions.py


示例2: test_delete_group_action

    def test_delete_group_action(self, users, groups):
        group = groups['group99']

        request = self.layer.new_request(type='json')
        with self.layer.authenticated('viewer'):
            self.expectError(
                HTTPForbidden,
                render_view_to_response,
                group,
                request,
                name='delete_item'
            )

        with self.layer.authenticated('admin'):
            res = render_view_to_response(group, request, name='delete_item')
        self.assertEqual(json.loads(res.text), {
            'message': "Deleted group from database",
            'success': True
        })

        with self.layer.authenticated('admin'):
            res = render_view_to_response(group, request, name='delete_item')
        self.assertEqual(json.loads(res.text), {
            'message': "u'group99'" if compat.IS_PY2 else "'group99'",
            'success': False
        })

        self.assertEqual(groups.keys(), [
            'group0', 'group1', 'group2', 'group3', 'group4', 'group5',
            'group6', 'group7', 'group8', 'group9', 'admin_group_1',
            'admin_group_2'
        ])
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:32,代码来源:test_browser_actions.py


示例3: test_after_outside_forms_context

    def test_after_outside_forms_context(self):
        import webob.multidict
        import schemaish
        from pyramid.view import render_view_to_response
        from pyramid_formish.zcml import FormAction
        from zope.configuration.config import ConfigurationMachine
        context = ConfigurationMachine()
        context.route_prefix = ''
        context.autocommit = True
        context.registry = self.config.registry
        request = testing.DummyRequest()
        request.registry = self.config.registry
        title = schemaish.String()
        factory = make_controller_factory(fields=[('title', title)])
        directive = self._makeOne(context, factory)
        directive._actions = [FormAction('submit','title',True)]
        directive.after()
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, '123')

        request = testing.DummyRequest()
        request.params = webob.multidict.MultiDict()
        request.params['submit'] = True
        display = render_view_to_response(None, request, '')
        self.assertEqual(display.body, 'submitted')
开发者ID:Pylons,项目名称:pyramid_formish,代码行数:25,代码来源:test_zcml.py


示例4: test_model_list

    def test_model_list(self):
        from ptah.manage.model import ModelModule, ModelView

        content = Content1()
        content.title = 'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1']

        res = render_view_to_response(model, DummyRequest(), '', False)
        self.assertIn('value="%s"'%rowid, res.text)

        res = render_view_to_response(
            model, DummyRequest(params={'batch': 0}), '', False)
        self.assertIn('value="%s"'%rowid, res.text)

        res = render_view_to_response(
            model, DummyRequest(params={'batch': 'unknown'}), '', False)
        self.assertIn('value="%s"'%rowid, res.text)
开发者ID:runyaga,项目名称:ptah,代码行数:25,代码来源:test_model.py


示例5: test_group_remove_user_action

    def test_group_remove_user_action(self, users, groups):
        group = groups['group99']
        group.model.add('uid99')
        group.model()

        request = self.layer.new_request(type='json')
        with self.layer.authenticated('viewer'):
            self.expectError(
                HTTPForbidden,
                render_view_to_response,
                group,
                request,
                name='remove_item'
            )

        request.params['id'] = 'uid100'
        with self.layer.authenticated('editor'):
            res = render_view_to_response(group, request, name='remove_item')
        self.assertEqual(json.loads(res.text), {
            'message': "u'uid100'" if compat.IS_PY2 else "'uid100'",
            'success': False
        })

        request.params['id'] = 'uid99'
        with self.layer.authenticated('editor'):
            res = render_view_to_response(group, request, name='remove_item')
        self.assertEqual(json.loads(res.text), {
            'message': "Removed user 'uid99' from group 'group99'.",
            'success': True
        })

        self.assertEqual(group.model.users, [])
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:32,代码来源:test_browser_actions.py


示例6: test_module_list

    def test_module_list(self):
        mod = self._make_mod()
        user = self._make_user()

        request = self.make_request(
            params = MultiDict(), POST = MultiDict())
        request.session['ptah-search-term'] = 'email'

        res = render_view_to_response(mod, request, '')

        self.assertIn('value="%s"'%user.id, res.text)

        res = render_view_to_response(
            mod,
            self.make_request(params = MultiDict(), POST = MultiDict()), '')

        self.assertIn('value="%s"'%user.id, res.text)

        res = render_view_to_response(
            mod,
            self.make_request(params = MultiDict({'batch': 1}),
                         POST = MultiDict()), '')

        self.assertIn('value="%s"'%user.id, res.text)

        res = render_view_to_response(
            mod,
            self.make_request(params = MultiDict({'batch': 0}),
                         POST = MultiDict()), '')

        self.assertIn('value="%s"'%user.id, res.text)
开发者ID:djedproject,项目名称:ptahcrowd,代码行数:31,代码来源:test_module.py


示例7: render_list

def render_list(context, request):
    request.orig_context = context
    name = request.POST['slot_name']
    if hasattr(context, 'slots'):
        for slot in context.slots:
            if slot.name == name and slot.snippets:
                snippets = request.snippets = list(slot.snippets)
                view_name = 'kottisnippets-list-%s' % name
                response = render_view_to_response(
                        snippets, 
                        request,
                        name=view_name)
                if response is None:
                    view_name = 'kottisnippets-list'
                    response = render_view_to_response(
                            snippets, 
                            request,
                            name=view_name)
                if response is None:
                    request.snippets = slot.snippets
                    return {
                            'slot_name': name,
                            'snippets': slot.snippets,
                           }
                return response
    raise PredicateMismatch()
开发者ID:rkintzi,项目名称:KottiSnippets,代码行数:26,代码来源:config.py


示例8: test_user_add_to_group_action

    def test_user_add_to_group_action(self, users, groups):
        user = users['uid99']

        request = self.layer.new_request(type='json')
        with self.layer.authenticated('viewer'):
            self.expectError(
                HTTPForbidden,
                render_view_to_response,
                user,
                request,
                name='add_item'
            )

        request.params['id'] = 'group99'
        with self.layer.authenticated('editor'):
            res = render_view_to_response(user, request, name='add_item')
        self.assertEqual(json.loads(res.text), {
            'message': "Added user 'uid99' to group 'group99'.",
            'success': True
        })

        request.params['id'] = 'group100'
        with self.layer.authenticated('editor'):
            res = render_view_to_response(user, request, name='add_item')
        self.assertEqual(json.loads(res.text), {
            'message': "u'group100'" if compat.IS_PY2 else "'group100'",
            'success': False
        })

        self.assertEqual(user.model.group_ids, ['group99'])
开发者ID:bluedynamics,项目名称:cone.ugm,代码行数:30,代码来源:test_browser_actions.py


示例9: test_sqla_table_view_model_nodes

    def test_sqla_table_view_model_nodes(self):
        from ptah.manage.sqla import SQLAModule, TableView

        rec = TestSqlaModuleContent(title='test')
        ptah.cms.Session.add(rec)
        ptah.cms.Session.flush()

        uri = rec.__uri__
        type_uri = rec.__type__.__uri__

        request = DummyRequest(params={'batch': 1})

        mod = SQLAModule(None, request)
        table = mod['psqla-ptah_nodes']

        res = render_view_to_response(table, request, '', False).text
        self.assertIn(url_quote_plus(uri), res)
        self.assertIn(url_quote_plus(type_uri), res)

        request = DummyRequest(params={'batch': 'unknown'})
        res = render_view_to_response(table, request, '', False).text
        self.assertIn(url_quote_plus(uri), res)

        request = DummyRequest(params={'batch': '0'})
        res = render_view_to_response(table, request, '', False).text
        self.assertIn(url_quote_plus(uri), res)
开发者ID:runyaga,项目名称:ptah,代码行数:26,代码来源:test_sqla.py


示例10: delegate_content_view

def delegate_content_view(context, request):
    delegate_view = getattr(context, 'delegate_view', False)
    if delegate_view:
        if delegate_view in context:
            return delegate_content_view(context[delegate_view], request)
    view_name = context.default_view and context.default_view or 'view'
    response = render_view_to_response(context, request, name=view_name)
    if response is None:  # pragma: no coverage
        warnings.warn("Failed to look up view called %r for %r." %
                      (view_name, context))
        response = render_view_to_response(context, request, name='view')
    return response
开发者ID:ArcheProject,项目名称:Arche,代码行数:12,代码来源:base.py


示例11: render_snippet

def render_snippet(context, request):
    name = request.POST['slot_name']
    view_name = 'kottisnippets-view-%s' % name
    response = render_view_to_response(context, request,
            name=view_name)
    if response is None:
        view_name = 'kottisnippets-view'
        response = render_view_to_response(context, request,
                name=view_name)
    if response is None:
        raise PredicateMismatch()
    return response
开发者ID:rkintzi,项目名称:KottiSnippets,代码行数:12,代码来源:config.py


示例12: signup

def signup(request):

    # TODO: figure out the right way to determine where the user is coming from
    # determine where user came from
    from_index = ('username' not in request.POST)
    from_agrement = request.POST.get('chkAgree','') == 'yes'

    if from_agrement:
        # redirect to the login form
        username = request.POST['username']
        login = request.route_url('login')
        login = '%s?username=%s' % (login, username)
        return HTTPFound(location=login)

    # get posted values and validate
    context = get_fields(request)
    if not from_index:
        context = validate_fields(context)
    valid = context['valid']

    # render the appropriate view
    if from_index or not valid:
        return render_view_to_response(context, request, name='signup-form')
    else:

        # create account
        first_name = context['first_name'].value
        last_name = context['last_name'].value
        username = context['username'].value
        display_name = '%s %s' % (first_name, last_name)
        password = context['password'].value
        recovery_key = KeyGen.generate_recovery_key()
        acct = Account(AccountType.Person, username, password, recovery_key)
        email_address = None
        mobile_phone = None

        # create person
        person = Person(first_name, last_name, email_address, mobile_phone, acct)

        # persist
        DBSession.add(person)
        transaction.commit()

        # TODO: create a pending flag to identify unconfirmed accounts

        context = {'recovery_key': recovery_key,
                   'username': username,
                   'display_name': display_name}

        return render_view_to_response(context, request, name='signup-complete')
开发者ID:alienlike,项目名称:courier,代码行数:50,代码来源:signup.py


示例13: follow_subrequest

def follow_subrequest(request, subrequest, **kwargs):
    """Run a subrequest (e.g. batch), and follow the redirection if any.

    :rtype: tuple
    :returns: the reponse and the redirection request (or `subrequest`
              if no redirection happened.)
    """
    try:
        try:
            return request.invoke_subrequest(subrequest, **kwargs), subrequest
        except Exception as e:
            resp = render_view_to_response(e, subrequest)
            if not resp or resp.status_code >= 500:
                raise e
            raise resp
    except httpexceptions.HTTPRedirection as e:
        new_location = e.headers["Location"]
        new_request = Request.blank(
            path=new_location,
            headers=subrequest.headers,
            POST=subrequest.body,
            method=subrequest.method,
        )
        new_request.bound_data = subrequest.bound_data
        new_request.parent = getattr(subrequest, "parent", None)
        return request.invoke_subrequest(new_request, **kwargs), new_request
开发者ID:pombredanne,项目名称:kinto,代码行数:26,代码来源:utils.py


示例14: call_second_view

        def call_second_view(name, status=True):
            DummyForm.status = status

            from pyramid.view import render_view_to_response
            request = testing.DummyRequest(matchdict=dict(name=name))
            context = None
            return render_view_to_response(context, request, name="second")
开发者ID:podhmo,项目名称:pyramid_selectable_renderer,代码行数:7,代码来源:tests.py


示例15: mimetype_view_selector

def mimetype_view_selector(context, request):
    mime_views = get_mimetype_views(request.registry)
    name = mime_views.get(context.mimetype, 'view')
    response = render_view_to_response(context, request, name = name)
    if response is None:
        raise HTTPNotFound()
    return response
开发者ID:Jickelsen,项目名称:Arche,代码行数:7,代码来源:file.py


示例16: render_view

def render_view(context, request, name='', secure=True):
    from kotti.security import authz_context

    with authz_context(context, request):
        response = render_view_to_response(context, request, name, secure)
    if response is not None:
        return response.ubody
开发者ID:disko,项目名称:Kotti,代码行数:7,代码来源:util.py


示例17: test_forbidden_user

    def test_forbidden_user(self):
        from ptahcrowd.forbidden import Forbidden

        class Context(object):
            """ """
            __name__ = 'test'

        request = self.request
        request.root = Context()
        ptah.auth_service.set_userid('user')

        class Principal(object):
            pass

        def get_principal():
            return Principal()

        orig = ptah.auth_service.get_current_principal
        ptah.auth_service.get_current_principal = get_principal

        res = render_view_to_response(HTTPForbidden(), request)
        ptah.auth_service.get_current_principal = orig

        self.assertEqual(text_(res.status), '403 Forbidden')
        self.assertIn(
            '<h1>Your are not allowed to access this part of site.</h1>',
            res.text)
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:27,代码来源:test_forbidden.py


示例18: test_layout_renderer

    def test_layout_renderer(self, m):
        import player

        m.choice.return_value = 'red'

        self.config.add_layout('test', view=View,
                               renderer='player:tests/test-layout.pt')
        self.config.add_view(
            name='view.html',
            renderer=player.layout('player:tests/dir1/view.pt', 'test'))

        from pyramid.view import render_view_to_response

        res1 = render_view_to_response(Context(), self.request, 'view.html')
        res2 = render_view_to_response(Context(), self.request, 'view.html')
        self.assertEqual(res1.text, res2.text)
        self.assertEqual('<div><h1>Test</h1></div>', res1.text.strip())
开发者ID:sidloki,项目名称:player,代码行数:17,代码来源:test_layout.py


示例19: delegate_content_view

def delegate_content_view(context, request):
    view_name = context.default_view and context.default_view or 'view'
    response = render_view_to_response(context, request, name=view_name)
    if response is None:  # pragma: no coverage
        warnings.warn("Failed to look up view called %r for %r." %
                      (view_name, context))
        raise HTTPNotFound()
    return response
开发者ID:Jickelsen,项目名称:Arche,代码行数:8,代码来源:base.py


示例20: test_settings_view

    def test_settings_view(self):
        from ptah.manage.settings import SettingsModule, SettingsView

        request = DummyRequest()

        mod = SettingsModule(None, request)

        res = render_view_to_response(mod, request, "", False)
        self.assertEqual(res.status, "200 OK")
开发者ID:runyaga,项目名称:ptah,代码行数:9,代码来源:test_settings.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyramid_basemodel.Session类代码示例发布时间:2022-05-27
下一篇:
Python view.render_view函数代码示例发布时间: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