Fix #356 with the new template
Created a custom template_filter as in python3, the groupby filter cannot order Bool vs Str. Needed to push format before the groupby which is not currently possible in jinja.
This commit is contained in:
@@ -78,6 +78,12 @@ def version():
|
|||||||
return __version__
|
return __version__
|
||||||
|
|
||||||
|
|
||||||
|
@app.template_filter()
|
||||||
|
def format_attribute(obj, attr, format_str):
|
||||||
|
setattr(obj, attr, format_str.format(getattr(obj, attr)))
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
def stream_template(template_name, **context):
|
def stream_template(template_name, **context):
|
||||||
app.update_template_context(context)
|
app.update_template_context(context)
|
||||||
t = app.jinja_env.get_template(template_name)
|
t = app.jinja_env.get_template(template_name)
|
||||||
|
|||||||
@@ -26,10 +26,10 @@
|
|||||||
]
|
]
|
||||||
{%- if render_graph %},
|
{%- if render_graph %},
|
||||||
"chart": [
|
"chart": [
|
||||||
{% for fact_h in facts | groupby('value') -%}
|
{% for fact_h in facts | map('format_attribute', 'value', '{0}') | groupby('value') -%}
|
||||||
{%- if not loop.first %},{%- endif -%}
|
{%- if not loop.first %},{%- endif -%}
|
||||||
{
|
{
|
||||||
"label": {{ fact_h.grouper.replace("\n", " ") | jsonprint }},
|
"label": {{ fact_h.grouper | replace("\n", " ") | jsonprint }},
|
||||||
"value": {{ fact_h.list|length }}
|
"value": {{ fact_h.list|length }}
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -699,7 +699,7 @@ def test_node_view(client, mocker,
|
|||||||
def test_fact_json_with_graph(client, mocker,
|
def test_fact_json_with_graph(client, mocker,
|
||||||
mock_puppetdb_environments,
|
mock_puppetdb_environments,
|
||||||
mock_puppetdb_default_nodes):
|
mock_puppetdb_default_nodes):
|
||||||
values = ['a', 'b', 'b', 'd']
|
values = ['a', 'b', 'b', 'd', True, 'a\nb']
|
||||||
query_data = {'facts': []}
|
query_data = {'facts': []}
|
||||||
query_data['facts'].append([])
|
query_data['facts'].append([])
|
||||||
for i, value in enumerate(values):
|
for i, value in enumerate(values):
|
||||||
@@ -720,14 +720,14 @@ def test_fact_json_with_graph(client, mocker,
|
|||||||
result_json = json.loads(rv.data.decode('utf-8'))
|
result_json = json.loads(rv.data.decode('utf-8'))
|
||||||
|
|
||||||
assert 'data' in result_json
|
assert 'data' in result_json
|
||||||
assert len(result_json['data']) == 4
|
assert len(result_json['data']) == 6
|
||||||
for line in result_json['data']:
|
for line in result_json['data']:
|
||||||
assert len(line) == 2
|
assert len(line) == 2
|
||||||
|
|
||||||
assert 'chart' in result_json
|
assert 'chart' in result_json
|
||||||
assert len(result_json['chart']) == 3
|
assert len(result_json['chart']) == 5
|
||||||
# Test group_by
|
# Test group_by
|
||||||
assert result_json['chart'][1]['value'] == 2
|
assert result_json['chart'][3]['value'] == 2
|
||||||
|
|
||||||
|
|
||||||
def test_fact_json_without_graph(client, mocker,
|
def test_fact_json_without_graph(client, mocker,
|
||||||
|
|||||||
Reference in New Issue
Block a user