本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, [])
示例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'
])
示例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')
示例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)
示例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, [])
示例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)
示例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()
示例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'])
示例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)
示例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
示例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
示例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')
示例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
示例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")
示例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