Skip to content

Commit

Permalink
fix: jinja safe html
Browse files Browse the repository at this point in the history
Closes #275
  • Loading branch information
sbrugman committed Jul 6, 2023
1 parent bf90a77 commit 4a93886
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions popmon/visualization/templates/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ <h4 class="card-title">{{metric.name | fmt_metric}}</h4>
</div>
<div id="{{ card_id }}"> </div>
{%- if metric.type in ['traffic_light', 'alert'] -%}
{{ metric.plot }}
{{ metric.plot | safe }}
{%- else -%}
<div class="skeleton-loader" id="{{ card_id }}-loading"></div>
<script>
rendered["{{ card_id }}"] = false;
render_func["{{ card_id }}"] = (function(){
var layout = deepCopy(layouts["{{ section_index }}{{ curr }}-{{ metric.type }}"]);
{%- if metric.shapes | length -%}
layout["shapes"] = {{ metric.shapes | json_plot}};
layout["shapes"] = {{ metric.shapes | json_plot | safe }};
{%- endif -%}
{%- if metric.yaxis_range | length -%}
layout["yaxis"]["range"] = {{ metric.yaxis_range | json_plot }};
layout["yaxis"]["range"] = {{ metric.yaxis_range | json_plot | safe }};
{%- endif -%}
Plotly.newPlot(document.getElementById("{{ card_id }}"), {{ metric.plot | json_plot }}, layout, plotly_config).then(function() { document.getElementById("{{ card_id }}-loading").remove(); rendered["{{ card_id }}"] = true;});
Plotly.newPlot(document.getElementById("{{ card_id }}"), {{ metric.plot | json_plot | safe }}, layout, plotly_config).then(function() { document.getElementById("{{ card_id }}-loading").remove(); rendered["{{ card_id }}"] = true;});
});

var io = new IntersectionObserver(function(entries) {
Expand Down
2 changes: 1 addition & 1 deletion popmon/visualization/templates/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var render_func = {};
</script>
{%- include 'header.html' -%}
{{ sections }}
{{ sections | safe }}
{%- include 'footer.html' -%}
</body>
</html>
4 changes: 2 additions & 2 deletions popmon/visualization/templates/section.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2>{{ section_title }}</h2>
<script>
{%- set curr = loop.index -%}
{%- for plot_type, layout in feature.plot_type_layouts.items() -%}
layouts["{{ section_index }}{{ curr }}-{{ plot_type }}"] = {{ layout | json_plot }};
layouts["{{ section_index }}{{ curr }}-{{ plot_type }}"] = {{ layout | json_plot | safe }};
{%- endfor -%}
</script>
<div class="section_feature" data-section-feature="{{ feature.name }}">
Expand Down Expand Up @@ -57,7 +57,7 @@ <h3> {{ feature.titles.get(ref, ref) }} </h3>
{%- for metric in plots -%}
<script>
{%- set curr = loop.index -%}
layouts["{{ section_index }}{{ curr }}-{{ metric.type }}"] = {{ metric.layout | json_plot }};
layouts["{{ section_index }}{{ curr }}-{{ metric.type }}"] = {{ metric.layout | json_plot | safe }};
</script>
{%- with metric=metric -%}
{%- include 'card.html' -%}
Expand Down

0 comments on commit 4a93886

Please sign in to comment.