Пример #1
0
 def index(self):
     try:
         template = self.j2.get_template('cm.j2')
     except:
         raise cp_api_404()
     env = {'build': eva.core.product.build}
     if eva.core.config.development:
         env['development'] = True
     return template.render(env)
Пример #2
0
Файл: ei.py Проект: alttch/eva3
 def index(self):
     try:
         template = self.j2.get_template('%s.j2' % eva.core.product.code)
     except:
         raise cp_api_404()
     env = {
         'build': eva.core.product.build,
         'product_name': eva.core.product.name,
         'product_code': eva.core.product.code
     }
     if eva.core.config.development:
         env['development'] = True
     return template.render(env)
Пример #3
0
def serve_j2(tpl_file, tpl_dir=eva.core.dir_ui):
    j2_loader = jinja2.FileSystemLoader(searchpath=tpl_dir)
    j2 = jinja2.Environment(loader=j2_loader)
    try:
        template = j2.get_template(tpl_file)
    except:
        raise cp_api_404()
    env = {}
    env['request'] = cherrypy.serving.request
    try:
        env['evaHI'] = 'evaHI ' in cherrypy.serving.request.headers.get(
            'User-Agent', '')
    except:
        env['evaHI'] = False
    try:
        k = cp_client_key(from_cookie=True, _aci=True)
    except:
        k = None
    if k:
        server_info = _get_api().test(k=k)[1]
    else:
        server_info = {}
    server_info['remote_ip'] = http_real_ip()
    env['server'] = server_info
    env.update(eva.core.cvars)
    template.globals['state'] = j2_state
    template.globals['groups'] = j2_groups
    template.globals['api_call'] = j2_api_call
    template.globals['get_aci'] = get_aci
    template.globals['import_module'] = importlib.import_module
    with _exposed_sfatpl_lock:
        for n, v in _exposed_sfatpl.items():
            template.globals[n] = v
    try:
        cherrypy.serving.response.headers[
            'Content-Type'] = 'text/html;charset=utf-8'
        return template.render(env).encode()
    except:
        eva.core.log_traceback()
        return 'Server error'