本文整理汇总了Python中pyramid.view.render_view函数的典型用法代码示例。如果您正苦于以下问题:Python render_view函数的具体用法?Python render_view怎么用?Python render_view使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_view函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RenderView
def RenderView(self, obj, name="", secure=True, raiseUnauthorized=False, codepage="utf-8"):
"""
Render a view for the object.
*name* is the name of the view to be looked up.
If *secure* is true permissions of the current user are checked against the view. If the
user lacks the necessary permissions and empty string is returned or if *raiseUnauthorized*
is True HTTPForbidden is raised.
returns rendered result
"""
# store original context to reset after calling render_view
orgctx = self.request.context
self.request.context = obj
if not raiseUnauthorized:
try:
value = render_view(obj, self.request, name, secure)
self.request.context = orgctx
except HTTPForbidden:
self.request.context = orgctx
return u""
else:
try:
value = render_view(obj, self.request, name, secure)
except:
self.request.context = orgctx
raise
self.request.context = orgctx
if not value:
return u""
return unicode(value, codepage)
示例2: response
def response(self):
page = int(self.request.params.get('page') or 0)
description_only = self.request.params.get('description_only', False)
catalog = find_catalog(self.context, 'system')
content_type = catalog['content_type']
query = content_type.eq(self.context.target_content_type)
if self.context.path is not None:
path = catalog['path']
query &= path.eq(self.context.path, include_origin=False)
resultset = [i for i in query.execute()]
resultset.sort(
key=attrgetter(self.context.sort_field),
reverse=self.context.sort_inverse)
if description_only:
resultset = [
{'title': e.title,
'name': e.name,
'description': e.short_description}
for e in resultset]
page_to_show = slice(None)
else:
resultset = [str(render_view(e, self.request)) for e in resultset]
page_to_show = slice(page, page + self.context.total_results or None)
return {
'title': self.context.title,
'text': self.context.text,
'items': resultset[page_to_show],
'page': page,
'pages': len(resultset),
}
示例3: __call__
def __call__(self):
with GitClone(self.request.base_repo_name, self.request.base_repo_url) as repo:
validationResults = self.validate(repo)
repo.merge(self.request.head_repo_url)
validationResutlsAfter = self.validate(repo)
validationView = render_view((validationResults, validationResutlsAfter),
self.request, 'view')
示例4: RenderView
def RenderView(self, obj, name="", secure=True, raiseUnauthorized=False, codepage="utf-8"):
"""
Render a view for the object.
*name* is the name of the view to be looked up.
If *secure* is true permissions of the current user are checked against the view. If the
user lacks the necessary permissions and empty string is returned or if *raiseUnauthorized*
is True HTTPForbidden is raised.
returns rendered result
"""
# store original context to reset after calling render_view
orgctx = self.request.context
orgresp = self.request.response
orgname = self.request.view_name
self.request.context = obj
self.request.response = Response()
self.request.view_name = name
try:
value = render_view(obj, self.request, name, secure)
if value is None:
value = ""
except HTTPNotFound:
value = "Not found!"
except HTTPForbidden:
value = ""
finally:
self.request.context = orgctx
self.request.response = orgresp
self.request.view_name = orgname
return unicode(value, codepage)
示例5: _render_view_on_slot_event
def _render_view_on_slot_event(view_name, event, params):
context = event.object
request = event.request
view_request = Request.blank(
"{0}/{1}".format(request.path.rstrip('/'), view_name),
base_url=request.application_url,
POST=_encode(params),
)
post_items = request.POST.items()
if post_items:
view_request.POST.extend(post_items)
# This is quite brittle:
for name in REQUEST_ATTRS_TO_COPY:
setattr(view_request, name, getattr(request, name))
try:
result = render_view(
context,
view_request,
view_name,
)
except PredicateMismatch:
return None
else:
return result.decode('utf-8')
示例6: _render_view_on_slot_event
def _render_view_on_slot_event(view_name, event, params):
context = event.object
request = event.request
view_request = request.__class__.blank(
"{0}/{1}".format(request.path.rstrip('/'), view_name),
base_url=request.application_url,
POST=_encode(params)
)
if request.POST:
view_request.POST.update(request.POST)
# This is quite brittle:
for name in REQUEST_ATTRS_TO_COPY:
setattr(view_request, name, getattr(request, name))
setattr(view_request, 'kotti_slot', event.name)
try:
result = render_view(context, view_request, view_name)
except (PredicateMismatch, HTTPForbidden):
return None
if isinstance(context, HTTPException):
return None
return result.decode('utf-8')
示例7: content
def content(self):
""" We may or may not use a complex layout... """
if not self.context.__data__['use_complex_layout']:
return self.context.__data__['text']
html = []
self.request.is_edit = self.is_edit
height = 0
for block in self.context.blocks:
try:
block_height = int(float(block.get("height", "200px")[:-2]))
block_top = int(float(block.get("top", "10px")[:-2]))
height = max(height, block_top + block_height)
except:
pass
html.append(render_view(block, self.request))
return """<div class="content" style="min-height: %spx">%s</div>""" \
% (height + 20, "".join(html))
示例8: build_chrome
def build_chrome(args):
"""
Build the Chrome extension. You can supply the base URL of an h
installation with which this extension will communicate, such as
"http://localhost:5000" (the default) when developing locally or
"https://hypothes.is" to talk to the production Hypothesis application.
By default, the extension will load static assets (JavaScript/CSS/etc.)
from the application you specify. This can be useful when developing, but
when building a production extension for deployment to the Chrome Store you
will need to specify an assets URL that links to the built assets within
the Chrome Extension, such as:
chrome-extension://<extensionid>/public
"""
paster.setup_logging(args.config_uri)
os.environ['WEBASSETS_BASE_DIR'] = os.path.abspath('./build/chrome/public')
if args.assets is not None:
os.environ['WEBASSETS_BASE_URL'] = args.assets
env = get_env(args.config_uri, args.base)
# Prepare a fresh build.
clean('build/chrome')
os.makedirs('build/chrome')
# Bundle the extension assets.
webassets_env = env['request'].webassets_env
content_dir = webassets_env.directory
os.makedirs(content_dir)
copytree('h/browser/chrome/content', 'build/chrome/content')
copytree('h/browser/chrome/help', 'build/chrome/help')
copytree('h/browser/chrome/images', 'build/chrome/images')
copytree('h/browser/chrome/lib', 'build/chrome/lib')
copytree('h/static/images', 'build/chrome/public/images')
shutil.copyfile(
'h/static/scripts/blocklist.js', 'build/chrome/lib/blocklist.js')
# Render the sidebar html.
if webassets_env.url.startswith('chrome-extension:'):
build_extension_common(env, bundle_app=True)
env['request'].layout_manager.layout.csp = ''
with open(content_dir + '/app.html', 'w') as fp:
data = render_view(env['root'], env['request'], 'viewer')
fp.write(data)
shutil.copyfile('h/static/icomoon.css',
'build/chrome/public/icomoon.css')
else:
build_extension_common(env)
# Render the manifest.
with open('build/chrome/manifest.json', 'w') as fp:
data = chrome_manifest(env['request'])
fp.write(data)
# Render the blocklist as a JSON file.
with open('build/chrome/blocklist.json', 'w') as fp:
fp.write(json.dumps(env['registry'].settings['h.blocklist']))
示例9: __call__
def __call__(self):
block = self._find_block()
if block:
return {'content': render_view(block, self.request)}
else:
return {'content': 'Not found'}
示例10: __call__
def __call__(self, name='', secure=True):
# Decode to utf8, else it's gonna throw UnicodeDecodeError
try:
return render_view(self.context, self.request, name, secure).decode("utf8")
except AttributeError:
#Handle none object
pass
return None
示例11: __call__
def __call__(self):
super(KeywordCloudView, self).__call__()
if 'clear' in self.request.GET:
CloudMaker(self.context, self.request).make_cloud(False)
return {'keyword_cloud': render_view(self.context,
self.request,
'keyword-cloud-image'),
}
示例12: embed
def embed(context, request):
assets_dir = request.webassets_env.directory
embed_file = join(assets_dir, 'js/embed.js')
setattr(request, 'view_name', 'embed.js')
with open(embed_file, 'w') as f:
f.write(render_view(context, request, name='embed.js'))
delattr(request, 'view_name')
示例13: content
def content(self):
html = []
for block in self.context.blocks:
html.append(render_view(block, self.request))
return "".join(html)
示例14: __call__
def __call__(self, name='', secure=True):
from pyramid.view import render_view
# Decode to utf8, else it's gonna throw UnicodeDecodeError
try:
return render_view(self.context, self.request,
name, secure).decode("utf8")
except AttributeError:
pass
return None
示例15: test_register_view
def test_register_view(self):
name = 'index.pt'
from pyramid_skins.configuration import register_path
register_path(self.config, os.path.join(path, 'skins'), indexes=[name])
from pyramid.testing import DummyRequest
from pyramid.view import render_view
response = render_view('Hello world!', DummyRequest(), "")
self.assertTrue(response is not None)