Merge pull request #4011 from hSaria/3313-config-context-gui

Fixes #3313: YAML-format the config context in the GUI
This commit is contained in:
Jeremy Stretch 2020-02-03 16:13:58 -05:00 committed by GitHub
commit fe22a8d0af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,11 @@
$('.rendered-context-format').on('click', function() {
if (!$(this).hasClass('active')) {
// Update selection in the button group
$('span.rendered-context-format').removeClass('active');
$('span.rendered-context-format[data-format=' + $(this).data('format') + ']').addClass('active');
// Hide all rendered contexts and only show the selected one
$('div.rendered-context-data').hide();
$('div.rendered-context-data[data-format=' + $(this).data('format') + ']').show();
}
});

View File

@ -1,5 +1,6 @@
{% extends '_base.html' %}
{% load helpers %}
{% load static %}
{% block header %}
<div class="row noprint">
@ -211,11 +212,16 @@
<div class="panel panel-default">
<div class="panel-heading">
<strong>Data</strong>
{% include 'extras/inc/configcontext_format.html' %}
</div>
<div class="panel-body">
<pre>{{ configcontext.data|render_json }}</pre>
{% include 'extras/inc/configcontext_data.html' with data=configcontext.data %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block javascript %}
<script src="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% load helpers %}
<div class="rendered-context-data" data-format="json">
<pre>{{ data|render_json }}</pre>
</div>
<div class="rendered-context-data" data-format="yaml" style="display: none;">
<pre>{{ data|render_yaml }}</pre>
</div>

View File

@ -0,0 +1,6 @@
<div class="pull-right">
<div class="btn-group btn-group-xs" role="group">
<span class="btn btn-default rendered-context-format active" data-format="json">JSON</span>
<span class="btn btn-default rendered-context-format" data-format="yaml">YAML</span>
</div>
</div>

View File

@ -1,5 +1,6 @@
{% extends base_template %}
{% load helpers %}
{% load static %}
{% block title %}{{ block.super }} - Config Context{% endblock %}
@ -9,9 +10,10 @@
<div class="panel panel-default">
<div class="panel-heading">
<strong>Rendered Context</strong>
{% include 'extras/inc/configcontext_format.html' %}
</div>
<div class="panel-body">
<pre>{{ rendered_context|render_json }}</pre>
{% include 'extras/inc/configcontext_data.html' with data=rendered_context %}
</div>
</div>
</div>
@ -22,7 +24,7 @@
</div>
<div class="panel-body">
{% if obj.local_context_data %}
<pre>{{ obj.local_context_data|render_json }}</pre>
{% include 'extras/inc/configcontext_data.html' with data=obj.local_context_data %}
{% else %}
<span class="text-muted">None</span>
{% endif %}
@ -47,7 +49,7 @@
{% if context.description %}
<br /><small>{{ context.description }}</small>
{% endif %}
<pre>{{ context.data|render_json }}</pre>
{% include 'extras/inc/configcontext_data.html' with data=context.data %}
</div>
{% empty %}
<div class="panel-body">
@ -58,3 +60,7 @@
</div>
</div>
{% endblock %}
{% block javascript %}
<script src="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}

View File

@ -1,6 +1,7 @@
import datetime
import json
import re
import yaml
from django import template
from django.utils.html import strip_tags
@ -76,6 +77,14 @@ def render_json(value):
return json.dumps(value, indent=4, sort_keys=True)
@register.filter()
def render_yaml(value):
"""
Render a dictionary as formatted YAML.
"""
return yaml.dump(dict(value))
@register.filter()
def model_name(obj):
"""