예제 #1
0
파일: main.py 프로젝트: andres-root/grow
def serve_console_reroute(pod, _request, _matched, **_kwargs):
    """Serve the default console page."""
    kwargs = {'pod': pod}
    env = ui.create_jinja_env()
    template = env.get_template('/views/base-reroute.html')
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #2
0
파일: main.py 프로젝트: grow/grow
def serve_console(pod, _request, _matched, **_kwargs):
    """Serve the default console page."""
    kwargs = {'pod': pod}
    env = ui.create_jinja_env()
    template = env.get_template('/views/base.html')
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #3
0
파일: rendered.py 프로젝트: Yzupnick/grow
 def _inject_ui(self, content, preprocessor):
     show_ui = (self.pod.env.name == env.Name.DEV and preprocessor
                and self.get_mimetype().endswith('html'))
     if show_ui:
         jinja_env = ui.create_jinja_env()
         ui_template = jinja_env.get_template('ui.html')
         content += '\n' + ui_template.render({
             'doc': self.doc,
             'preprocessor': preprocessor,
         })
     return content
예제 #4
0
 def _inject_ui(self, content, preprocessor, translator):
     show_ui = (self.pod.env.name == env.Name.DEV
                and (preprocessor or translator)
                and self.get_mimetype().endswith('html'))
     if show_ui:
         jinja_env = ui.create_jinja_env()
         ui_template = jinja_env.get_template('ui.html')
         content += '\n' + ui_template.render({
             'doc': self.doc,
             'preprocessor': preprocessor,
             'translator': translator,
         })
     return content
예제 #5
0
파일: main.py 프로젝트: andres-root/grow
def serve_editor_reroute(pod, _request, matched, meta=None, **_kwargs):
    """Serve the default console page."""
    kwargs = {
        'pod': pod,
        'meta': meta,
        'path': matched.params['path'] if 'path' in matched.params else '',
    }
    env = ui.create_jinja_env()
    template = env.get_template('/views/editor.html')
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #6
0
파일: main.py 프로젝트: grow/grow
def serve_editor(pod, _request, matched, meta=None, **_kwargs):
    """Serve the default console page."""
    kwargs = {
        'pod': pod,
        'meta': meta,
        'path': matched.params['path'] if 'path' in matched.params else '',
    }
    env = ui.create_jinja_env()
    template = env.get_template('/views/editor.html')
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #7
0
 def _inject_ui(self, content, preprocessor, translator, ui_settings):
     # TODO Enable the ui when the ui option is enabled in deploy settings.
     show_ui = (self.pod.env.name == env.Name.DEV
                and (preprocessor or translator)
                and self.get_mimetype().endswith('html'))
     if show_ui:
         jinja_env = ui.create_jinja_env()
         ui_template = jinja_env.get_template('ui.html')
         content += '\n' + ui_template.render({
             'doc': self.doc,
             'preprocessor': preprocessor,
             'translator': translator,
             'ui': ui_settings,
         })
     return content
예제 #8
0
 def _create_response(pod, routes, title, is_concrete=True):
     env = ui.create_jinja_env()
     template = env.get_template('views/base.html')
     kwargs = {
         'pod': pod,
         'partials': [{
             'partial': 'routes',
             'is_concrete': is_concrete,
             'routes': routes,
         }],
         'title': title,
     }
     content = template.render(kwargs)
     response = wrappers.Response(content)
     response.headers['Content-Type'] = 'text/html'
     return response
예제 #9
0
 def serve_routes(pod, _request, _matched):
     """Handle the request for routes."""
     env = ui.create_jinja_env()
     template = env.get_template('views/base-reroute.html')
     kwargs = {
         'pod': pod,
         'partials': [{
             'partial': 'routes',
             'routes': pod.router.routes,
         }],
         'title': 'Pod Routes',
     }
     content = template.render(kwargs)
     response = wrappers.Response(content)
     response.headers['Content-Type'] = 'text/html'
     return response
예제 #10
0
파일: handlers.py 프로젝트: uxder/grow
def serve_exception(pod, request, exc, **_kwargs):
    """Serve the exception page."""
    debug = True
    log = logging.exception
    if isinstance(exc, webob_exc.HTTPException):
        status = exc.status_int
        log('{}: {}'.format(status, request.path))
    elif isinstance(exc, errors.RouteNotFoundError):
        status = 404
        log('{}: {}'.format(status, request.path))
    elif isinstance(exc, NotFound):
        status = 404
        log('{}: {}'.format(status, request.path))
    else:
        status = 500
        log('{}: {} - {}'.format(status, request.path, exc))
    env = ui.create_jinja_env()
    template = env.get_template('/views/error.html')
    if (isinstance(exc, errors.BuildError)):
        t_back = exc.traceback
    else:
        unused_error_type, unused_value, t_back = sys.exc_info()
    formatted_traceback = [
        re.sub('^  ', '', line) for line in traceback.format_tb(t_back)
    ]
    formatted_traceback = '\n'.join(formatted_traceback)
    kwargs = {
        'exception': exc,
        'is_web_exception': isinstance(exc, webob_exc.HTTPException),
        'pod': pod,
        'status': status,
        'traceback': formatted_traceback,
    }
    home_doc = pod.get_home_doc()
    if home_doc and home_doc.exists:
        kwargs['home_url'] = home_doc.url.path
    if (isinstance(exc, errors.BuildError)):
        kwargs['build_error'] = exc.exception
    if (isinstance(exc, errors.BuildError)
            and isinstance(exc.exception, jinja2.TemplateSyntaxError)):
        kwargs['template_exception'] = exc.exception
    elif isinstance(exc, jinja2.TemplateSyntaxError):
        kwargs['template_exception'] = exc
    content = template.render(**kwargs)
    response = wrappers.Response(content, status=status)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #11
0
def serve_console(pod, request, values):
    kwargs = {'pod': pod}
    values_to_templates = {
        'content': 'collections.html',
        'translations': 'catalogs.html',
    }
    value = values.get('page')
    template_path = values_to_templates.get(value, 'main.html')
    if value == 'translations' and values.get('locale'):
        kwargs['locale'] = values.get('locale')
        template_path = 'catalog.html'
    env = ui.create_jinja_env()
    template = env.get_template(template_path)
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #12
0
파일: main.py 프로젝트: grow/grow
 def handle_exception(self, request, exc):
     self.debug = True
     log = logging.exception if self.debug else self.pod.logger.error
     if isinstance(exc, webob_exc.HTTPException):
         status = exc.status_int
         log('{}: {}'.format(status, request.path))
     elif isinstance(exc, errors.RouteNotFoundError):
         status = 404
         log('{}: {}'.format(status, request.path))
     else:
         status = 500
         log('{}: {} - {}'.format(status, request.path, exc))
     env = ui.create_jinja_env()
     template = env.get_template('/views/error.html')
     if (isinstance(exc, errors.BuildError)):
         tb = exc.traceback
     else:
         unused_error_type, unused_value, tb = sys.exc_info()
     formatted_traceback = [
         re.sub('^  ', '', line)
         for line in traceback.format_tb(tb)]
     formatted_traceback = '\n'.join(formatted_traceback)
     kwargs = {
         'exception': exc,
         'is_web_exception': isinstance(exc, webob_exc.HTTPException),
         'pod': self.pod,
         'status': status,
         'traceback': formatted_traceback,
     }
     try:
         home_doc = self.pod.get_home_doc()
         if home_doc:
             kwargs['home_url'] = home_doc.url.path
     except:
         pass
     if (isinstance(exc, errors.BuildError)):
         kwargs['build_error'] = exc.exception
     if (isinstance(exc, errors.BuildError)
             and isinstance(exc.exception, jinja2.TemplateSyntaxError)):
         kwargs['template_exception'] = exc.exception
     elif isinstance(exc, jinja2.TemplateSyntaxError):
         kwargs['template_exception'] = exc
     content = template.render(**kwargs)
     response = wrappers.Response(content, status=status)
     response.headers['Content-Type'] = 'text/html'
     return response
예제 #13
0
파일: main.py 프로젝트: Yzupnick/grow
def serve_console(pod, request, values):
    kwargs = {'pod': pod}
    values_to_templates = {
        'content': 'collections.html',
        'translations': 'catalogs.html',
    }
    value = values.get('page')
    template_path = values_to_templates.get(value, 'main.html')
    if value == 'translations' and values.get('locale'):
        kwargs['locale'] = values.get('locale')
        template_path = 'catalog.html'
    env = ui.create_jinja_env()
    template = env.get_template(template_path)
    content = template.render(kwargs)
    response = wrappers.Response(content)
    response.headers['Content-Type'] = 'text/html'
    return response
예제 #14
0
 def handle_exception(self, request, exc):
     log = logging.exception if self.debug else self.pod.logger.error
     if isinstance(exc, webob_exc.HTTPException):
         status = exc.status_int
         log('{}: {}'.format(status, request.path))
     else:
         status = 500
         log('{}: {} - {}'.format(status, request.path, exc))
     env = ui.create_jinja_env()
     template = env.get_template('error.html')
     if (isinstance(exc, errors.BuildError)):
         tb = exc.traceback
     else:
         unused_error_type, unused_value, tb = sys.exc_info()
     formatted_traceback = [
         re.sub('^  ', '', line) for line in traceback.format_tb(tb)
     ]
     formatted_traceback = '\n'.join(formatted_traceback)
     kwargs = {
         'exception': exc,
         'is_web_exception': isinstance(exc, webob_exc.HTTPException),
         'pod': self.pod,
         'status': status,
         'traceback': formatted_traceback,
     }
     try:
         home_doc = self.pod.get_home_doc()
         if home_doc:
             kwargs['home_url'] = home_doc.url.path
     except:
         pass
     if (isinstance(exc, errors.BuildError)):
         kwargs['build_error'] = exc.exception
     if (isinstance(exc, errors.BuildError)
             and isinstance(exc.exception, jinja2.TemplateSyntaxError)):
         kwargs['template_exception'] = exc.exception
     elif isinstance(exc, jinja2.TemplateSyntaxError):
         kwargs['template_exception'] = exc
     content = template.render(**kwargs)
     response = wrappers.Response(content, status=status)
     response.headers['Content-Type'] = 'text/html'
     return response