Add a new jsonprint filter, used in metrics, query

This commit is contained in:
Daniele Sluijters
2013-11-05 16:41:47 +01:00
parent 79ac5b3cb0
commit efe488aafc
4 changed files with 14 additions and 3 deletions

View File

@@ -18,7 +18,7 @@ from pypuppetdb import connect
from puppetboard.forms import QueryForm
from puppetboard.utils import (
get_or_abort, yield_or_stop,
ten_reports,
ten_reports, jsonprint
)
@@ -27,6 +27,8 @@ app.config.from_object('puppetboard.default_settings')
app.config.from_envvar('PUPPETBOARD_SETTINGS', silent=True)
app.secret_key = os.urandom(24)
app.jinja_env.filters['jsonprint'] = jsonprint
puppetdb = connect(
api_version=3,
host=app.config['PUPPETDB_HOST'],

View File

@@ -11,7 +11,11 @@
{% for key,value in metric %}
<tr>
<td>{{key}}</td>
{% if value is mapping %}
<td><pre>{{value|jsonprint}}</pre></td>
{% else %}
<td>{{value}}</td>
{% endif %}
</tr>
{% endfor %}
</tbody>

View File

@@ -53,7 +53,7 @@
<div class="row">
<div class="span12">
<h2>Result</h2>
<pre><code>{{ result|tojson|replace(", ", ",\n") }}</code></pre>
<pre><code>{{result|jsonprint}}</code></pre>
</div>
</div>
{% endif %}

View File

@@ -1,11 +1,16 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import json
from requests.exceptions import HTTPError, ConnectionError
from pypuppetdb.errors import EmptyResponseError
from flask import abort
def jsonprint(value):
return json.dumps(value, indent=2, separators=(',', ': ') )
def get_or_abort(func, *args, **kwargs):
"""Execute the function with its arguments and handle the possible