Skip to content

Commit

Permalink
Added json_render method to separate filtering from view (#14024)
Browse files Browse the repository at this point in the history
  • Loading branch information
VBhojawala authored Feb 4, 2021
1 parent 84ef24c commit e2a06a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 12 additions & 1 deletion airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def render(obj, lexer):
return out


def json_render(obj, lexer):
"""Render a given Python object with json lexer"""
out = ""
if isinstance(obj, str):
out = Markup(pygment_html_render(obj, lexer))
elif isinstance(obj, (dict, list)):
content = json.dumps(obj, sort_keys=True, indent=4)
out = Markup(pygment_html_render(content, lexer))
return out


def wrapped_markdown(s, css_class=None):
"""Convert a Markdown string to HTML."""
if s is None:
Expand All @@ -343,7 +354,7 @@ def get_attr_renderer():
'doc_rst': lambda x: render(x, lexers.RstLexer),
'doc_yaml': lambda x: render(x, lexers.YamlLexer),
'doc_md': wrapped_markdown,
'json': lambda x: render(x, lexers.JsonLexer),
'json': lambda x: json_render(x, lexers.JsonLexer),
'md': wrapped_markdown,
'py': lambda x: render(get_python_source(x), lexers.PythonLexer),
'python_callable': lambda x: render(get_python_source(x), lexers.PythonLexer),
Expand Down
2 changes: 0 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,6 @@ def rendered_templates(self):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field, template_field)
if renderer in renderers:
if isinstance(content, (dict, list)):
content = json.dumps(content, sort_keys=True, indent=4)
html_dict[template_field] = renderers[renderer](content)
else:
html_dict[template_field] = Markup("<pre><code>{}</pre></code>").format(
Expand Down

0 comments on commit e2a06a3

Please sign in to comment.