本文整理汇总了Python中pylons.templating.render函数的典型用法代码示例。如果您正苦于以下问题:Python render函数的具体用法?Python render怎么用?Python render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: listAllAppLogDir
def listAllAppLogDir(service, manifest, package, shortDirName, packagePathStr, appLogDirList):
""" listAllAppLogDir """
if (len(appLogDirList) < 1):
c.errorMsg = 'Could not find logDirs config values in config file %s' % (appLogDirList)
c.errorCode = Errors.LOG_APP_DIR_CONFIG_MISSING
return render('/derived/error.html')
for fileName in appLogDirList:
if (not os.path.exists(os.path.join(packagePathStr, fileName))):
c.errorMsg = 'App Log directory (%s) missing' % (fileName)
c.errorCode = Errors.LOG_APP_DIR_NOT_FOUND
return render('/derived/error.html')
if (request.environ['CONTENT_TYPE'] == 'application/json'):
return ApplogController.doJSonStr(appLogDirList)
else:
fullLogList = []
for fileName in appLogDirList:
logList = ApplogController.getAppLogEntryHtml(
service, manifest, package, shortDirName, packagePathStr, fileName)
fullLogList.append(logList)
c.status = fullLogList
c.message = "List Of Files/Directories"
c.absolutePath = packagePathStr
c.menuTab = 'MENU_TAB_APPLOGS'
return render('/derived/appLogDirectory.html')
示例2: login
def login(self):
'''
This is the redirect of the first template
'''
param = request.params
c.defaultRealm = getDefaultRealm()
c.p = {}
c.user = ""
c.title = "LinOTP OpenID Service"
for k in param:
c.p[k] = param[k]
if "openid.claimed_id" == k:
c.user = param[k].rsplit("/", 1)[1]
## if we have already a cookie but
## a difference between login and cookie user
## we show (via /status) that he is already logged in
## and that he first must log out
cookie = request.cookies.get(COOKIE_NAME)
if cookie is not None:
cookie_user, token = cookie.split(":")
if cookie_user != c.user:
c.login = cookie_user
c.message = ("Before logging in as >%s< you have to log out."
% (c.user))
return render("/openid/status.mako")
return render('/openid/login.mako')
示例3: doManifestLogFile
def doManifestLogFile(action):
""" do manifest log file """
service = request.params.get('service', '')
package = request.params.get('package', '')
manifest = request.params.get('manifest', 'active')
if (service == '' or package == ''):
c.errorMsg = 'missing service or package parameter from request'
c.errorCode = Errors.LOG_PARAM_REQUIRED
return render('/derived/error.html')
print 'service/package/manifest ', service, package, manifest
packagePathStr = packagePath(service, package, manifest)
print 'package path ', packagePathStr
pkgInit = PkgInitConfig(service, package, manifest)
pkgConfig = pkgInit.getConfigs()
if not pkgConfig:
c.errorMsg = 'cronus.ini does not exist, view log needs cronus.ini to know log location, please check your cronus package to make sure cronus.ini exist and have property logAppDir'
c.errorCode = Errors.CRONUS_INI_EMPTY_NOT_FOUND
return render('/derived/error.html')
print '*** packageConfig ', pkgConfig
manifestFileName = pkgConfig['logManifestFile']
if (action == 'download'):
return downloadFile(os.path.join(packagePathStr, manifestFileName))
if (action == 'tail'):
lines = request.params.get('size', '100')
return tailFile(os.path.join(packagePathStr, manifestFileName), lines)
if (action == 'list'):
return manifestFileName
示例4: listAppLogDir
def listAppLogDir(service, manifest, package, shortDirName, dirName):
""" listAppLogDir """
LOG.debug('In ApplogController dirName ' + dirName)
contentType = request.environ['CONTENT_TYPE']
if (not os.path.exists(dirName)):
c.errorMsg = 'App Log directory (%s) missing' % (dirName)
c.errorCode = Errors.LOG_APP_DIR_NOT_FOUND
return render('/derived/error.html')
if (os.path.isfile(dirName)):
if contentType == 'text/plain':
return downloadFile(dirName)
else:
return viewFile(dirName)
if (os.path.isdir(dirName)):
logList = os.listdir(dirName)
if contentType == 'application/json':
return ApplogController.doJSonStr(logList)
else:
fullLogList = []
for fileName in logList:
logList = ApplogController.getAppLogEntryHtml(
service, manifest, package, shortDirName, dirName, fileName)
fullLogList.append(logList)
c.status = fullLogList
c.message = "List Of Files/Directories" + ""
c.absolutePath = dirName
c.menuTab = 'MENU_TAB_APPLOGS'
return render('/derived/appLogDirectory.html')
示例5: cache_content
def cache_content(self, key, do_work, template):
"""Argh!
Okay, so. Use this when you want to cache the BODY of a page but not
the CHROME (i.e., wrapper or base or whatever).
``key``
The key that uniquely identifies this particular rendering of this
page content.
``do_work``
Some function that will stuff a bunch of expensive data in c. This
will only be called if the page hasn't yet been cached. It'll be
passed the key.
``template``
Name of the template to use.
Also, DO NOT FORGET TO wrap the cachable part of your template in a
<%lib:cache_content> tag, or nothing will get cached!
If a page body is pulled from cache, c.timer.from_cache will be set to
True. If the page had to be generated, it will be set to False. (If
this function wasn't involved at all, it will be set to None.)
"""
# Content needs to be cached per-language
key = u"{0}/{1}".format(key, c.lang)
# Cache for... ten hours? Sure, whatever
content_cache = cache.get_cache("content_cache:" + template, expiretime=36000)
# XXX This is dumb. Caches don't actually respect the 'enabled'
# setting, so we gotta fake it.
if not content_cache.nsargs.get("enabled", True):
def skip_cache(context, mako_def):
do_work(key)
mako_def.body()
c._cache_me = skip_cache
return render(template)
# These pages can be pretty big. In the case of e.g. memcached, that's
# a lot of RAM spent on giant pages that consist half of whitespace.
# Solution: gzip everything. Use level 1 for speed!
def cache_me(context, mako_def):
c.timer.from_cache = True
def generate_page():
c.timer.from_cache = False
do_work(key)
return zlib.compress(capture(context, mako_def.body).encode("utf8"), 1)
context.write(zlib.decompress(content_cache.get_value(key=key, createfunc=generate_page)).decode("utf8"))
c._cache_me = cache_me
return render(template)
示例6: add_dynamic_selfservice_enrollment
def add_dynamic_selfservice_enrollment(config, actions):
'''
add_dynamic_actions - load the html of the dynamic tokens
according to the policy definition
:param actions: the allowd policy actions for the current scope
:type actions: array of actions names
:return: hash of {tokentype : html for tab}
'''
dynanmic_actions = {}
g = config['pylons.app_globals']
tokenclasses = g.tokenclasses
for tok in tokenclasses.keys():
tclass = tokenclasses.get(tok)
tclass_object = newToken(tclass)
if hasattr(tclass_object, 'getClassInfo'):
try:
selfservice = tclass_object.getClassInfo('selfservice', ret=None)
# # check if we have a policy in the token definition for the enroll
if selfservice.has_key('enroll') and 'enroll' + tok.upper() in actions:
service = selfservice.get('enroll')
tab = service.get('title')
c.scope = tab.get('scope')
t_file = tab.get('html')
t_html = render(t_file)
''' remove empty lines '''
t_html = '\n'.join([line for line in t_html.split('\n') if line.strip() != ''])
e_name = "%s.%s.%s" % (tok, 'selfservice', 'enroll')
dynanmic_actions[e_name] = t_html
# # check if there are other selfserive policy actions
policy = tclass_object.getClassInfo('policy', ret=None)
if 'selfservice' in policy:
selfserv_policies = policy.get('selfservice').keys()
for action in actions:
if action in selfserv_policies:
# # now lookup, if there is an additional section
# # in the selfservice to render
service = selfservice.get(action)
tab = service.get('title')
c.scope = tab.get('scope')
t_file = tab.get('html')
t_html = render(t_file)
''' remove empty lines '''
t_html = '\n'.join([line for line in t_html.split('\n') if line.strip() != ''])
e_name = "%s.%s.%s" % (tok, 'selfservice', action)
dynanmic_actions[e_name] = t_html
except Exception as e:
log.info('[_add_dynamic_actions] no policy for tokentype '
'%s found (%r)' % (unicode(tok), e))
return dynanmic_actions
示例7: add_dynamic_selfservice_enrollment
def add_dynamic_selfservice_enrollment(config, actions):
"""
add_dynamic_actions - load the html of the dynamic tokens
according to the policy definition
:param actions: the allowd policy actions for the current scope
:type actions: array of actions names
:return: hash of {tokentype : html for tab}
"""
dynanmic_actions = {}
g = config["pylons.app_globals"]
tokenclasses = g.tokenclasses
for tok in tokenclasses.keys():
tclass = tokenclasses.get(tok)
tclass_object = newToken(tclass)
if hasattr(tclass_object, "getClassInfo"):
try:
selfservice = tclass_object.getClassInfo("selfservice", ret=None)
# # check if we have a policy in the token definition for the enroll
if selfservice.has_key("enroll") and "enroll" + tok.upper() in actions:
service = selfservice.get("enroll")
tab = service.get("title")
c.scope = tab.get("scope")
t_file = tab.get("html")
t_html = render(t_file)
""" remove empty lines """
t_html = "\n".join([line for line in t_html.split("\n") if line.strip() != ""])
e_name = "%s.%s.%s" % (tok, "selfservice", "enroll")
dynanmic_actions[e_name] = t_html
# # check if there are other selfserive policy actions
policy = tclass_object.getClassInfo("policy", ret=None)
if "selfservice" in policy:
selfserv_policies = policy.get("selfservice").keys()
for action in actions:
if action in selfserv_policies:
# # now lookup, if there is an additional section
# # in the selfservice to render
service = selfservice.get(action)
tab = service.get("title")
c.scope = tab.get("scope")
t_file = tab.get("html")
t_html = render(t_file)
""" remove empty lines """
t_html = "\n".join([line for line in t_html.split("\n") if line.strip() != ""])
e_name = "%s.%s.%s" % (tok, "selfservice", action)
dynanmic_actions[e_name] = t_html
except Exception as e:
log.info("[_add_dynamic_actions] no policy for tokentype " "%s found (%r)" % (unicode(tok), e))
return dynanmic_actions
示例8: _getTokenTypeConfig
def _getTokenTypeConfig(section='config'):
'''
_getTokenTypeConfig - retrieve from the dynamic token the
tokentype section, eg. config or enroll
:param section: the section of the tokentypeconfig
:type section: string
:return: dict with tab and page definition (rendered)
:rtype: dict
'''
res = {}
g = config['pylons.app_globals']
tokenclasses = g.tokenclasses
for tok in tokenclasses.keys():
tclass = tokenclasses.get(tok)
tclass_object = newToken(tclass)
if hasattr(tclass_object, 'getClassInfo'):
conf = tclass_object.getClassInfo(section, ret={})
## set globale render scope, so that the mako
## renderer will return only a subsection from the template
p_html = ''
t_html = ''
try:
page = conf.get('page')
c.scope = page.get('scope')
p_html = render(os.path.sep + page.get('html'))
p_html = remove_empty_lines(p_html)
tab = conf.get('title')
c.scope = tab.get('scope')
t_html = render(os.path.sep + tab.get('html'))
t_html = remove_empty_lines(t_html)
except CompileException as ex:
log.error("[_getTokenTypeConfig] compile error while processing %r.%r:" % (tok, section))
log.error("[_getTokenTypeConfig] %r" % ex)
log.error("[_getTokenTypeConfig] %s" % traceback.format_exc())
raise Exception(ex)
except Exception as e:
log.debug('no config for token type %r (%r)' % (tok, e))
p_html = ''
if len (p_html) > 0:
res[tok] = { 'html' : p_html, 'title' : t_html}
return res
示例9: _getTokenTypeConfig
def _getTokenTypeConfig(section="config"):
"""
_getTokenTypeConfig - retrieve from the dynamic token the
tokentype section, eg. config or enroll
:param section: the section of the tokentypeconfig
:type section: string
:return: dict with tab and page definition (rendered)
:rtype: dict
"""
res = {}
g = config["pylons.app_globals"]
tokenclasses = g.tokenclasses
for tok in tokenclasses.keys():
tclass = tokenclasses.get(tok)
tclass_object = newToken(tclass)
if hasattr(tclass_object, "getClassInfo"):
conf = tclass_object.getClassInfo(section, ret={})
## set globale render scope, so that the mako
## renderer will return only a subsection from the template
p_html = ""
t_html = ""
try:
page = conf.get("page")
c.scope = page.get("scope")
p_html = render(os.path.sep + page.get("html"))
p_html = remove_empty_lines(p_html)
tab = conf.get("title")
c.scope = tab.get("scope")
t_html = render(os.path.sep + tab.get("html"))
t_html = remove_empty_lines(t_html)
except CompileException as ex:
log.exception("[_getTokenTypeConfig] compile error while processing %r.%r:" % (tok, section))
log.error("[_getTokenTypeConfig] %r" % ex)
raise Exception(ex)
except Exception as e:
log.debug("no config for token type %r (%r)" % (tok, e))
p_html = ""
if len(p_html) > 0:
res[tok] = {"html": p_html, "title": t_html}
return res
示例10: document
def document(self):
"""Render the error document"""
resp = request.environ.get('pylons.original_response')
content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
code = resp.status_int
if code == 404:
return render('/404.mako')
elif code == 500:
return render('/500.mako')
page = error_document_template % \
dict(prefix=request.environ.get('SCRIPT_NAME', ''),
code=cgi.escape(request.GET.get('code', str(resp.status_int))),
message=content)
return page
示例11: render
def render(self, **kwargs):
'''Override FormAlchemy rendering to use a Ckan template'''
if hasattr(self, 'form_template') and self.form_template is not None:
c.fieldset = self
return render(self.form_template)
else:
return formalchemy.FieldSet.render(self, **kwargs)
示例12: document
def document(self):
"""Render the error document"""
resp = request.environ.get('pylons.original_response')
content = literal(resp.body) or cgi.escape(request.GET.get('message', ''))
c.code=cgi.escape(request.GET.get('code', str(resp.status_int)))
c.message = content
return render('error/error.mako')
示例13: login
def login(self):
log.debug("[login] selfservice login screen")
identity = request.environ.get('repoze.who.identity')
if identity is not None:
# After login We always redirect to the start page
redirect("/")
res = {}
try:
c.defaultRealm = getDefaultRealm()
res = getRealms()
c.realmArray = []
#log.debug("[login] %s" % str(res) )
for (k, v) in res.items():
c.realmArray.append(k)
c.realmbox = getRealmBox()
log.debug("[login] displaying realmbox: %i" % int(c.realmbox))
Session.commit()
response.status = '%i Logout from LinOTP selfservice' % LOGIN_CODE
return render('/selfservice/login.mako')
except Exception as e:
log.exception('[login] failed %r' % e)
Session.rollback()
return sendError(response, e)
finally:
Session.close()
示例14: get_my_apps
def get_my_apps(self):
"""
Returns the list of registered apps
"""
user = pylons.request.environ['fts3.User.Credentials']
my_apps = Session.query(OAuth2Application).filter(OAuth2Application.owner == user.user_dn).all()
authorized_apps = Session.query(
OAuth2Application.client_id, OAuth2Application.name, OAuth2Application.website,
OAuth2Application.description, OAuth2Token.refresh_token, OAuth2Token.scope, OAuth2Token.expires
).filter((OAuth2Token.dlg_id == user.delegation_id) & (OAuth2Token.client_id == OAuth2Application.client_id))
response = {'apps': my_apps, 'authorized': authorized_apps}
if _accept_html(pylons.request.accept):
pylons.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
response['user'] = user
response['site'] = pylons.config['fts3.SiteName']
return render('/apps.html', extra_vars=response)
else:
pylons.response.headers['Content-Type'] = 'application/json'
# Better serialization for authorized apps
authorized = list()
for auth in authorized_apps:
authorized.append({
'name': auth.name,
'website': auth.website,
'description': auth.description,
'scope': auth.scope,
'expires': auth.expires
})
response['authorized'] = authorized
return to_json(response)
示例15: view
def view(self, id):
"""
The primary view page for an organism
"""
organism_guid = id
credentials = m.login("kconragan", "dulcev1da")
query = {
"*" : None,
"guid" : '#' + id,
"type" : "/user/kconragan/scuba_diving/marine_creature",
"/common/topic/article" : [{}],
"/common/topic/image" : [{}]
}
c.content = m.read(query, credentials)
related_query = [{
"higher_classification" : c.content['higher_classification'],
"name" : [],
"guid" : None,
"type" : "/biology/organism_classification"
}]
c.related = m.read(related_query, credentials)
return render('/derived/organism/view.html')