File tree 6 files changed +50
-4
lines changed
6 files changed +50
-4
lines changed Original file line number Diff line number Diff line change
1
+ $ ( '.rendered-context-format' ) . on ( 'click' , function ( ) {
2
+ if ( ! $ ( this ) . hasClass ( 'active' ) ) {
3
+ // Update selection in the button group
4
+ $ ( 'span.rendered-context-format' ) . removeClass ( 'active' ) ;
5
+ $ ( 'span.rendered-context-format[data-format=' + $ ( this ) . data ( 'format' ) + ']' ) . addClass ( 'active' ) ;
6
+
7
+ // Hide all rendered contexts and only show the selected one
8
+ $ ( 'div.rendered-context-data' ) . hide ( ) ;
9
+ $ ( 'div.rendered-context-data[data-format=' + $ ( this ) . data ( 'format' ) + ']' ) . show ( ) ;
10
+ }
11
+ } ) ;
Original file line number Diff line number Diff line change 1
1
{% extends '_base.html' %}
2
2
{% load helpers %}
3
+ {% load static %}
3
4
4
5
{% block header %}
5
6
< div class ="row noprint ">
@@ -211,11 +212,16 @@ <h1>{% block title %}{{ configcontext }}{% endblock %}</h1>
211
212
< div class ="panel panel-default ">
212
213
< div class ="panel-heading ">
213
214
< strong > Data</ strong >
215
+ {% include 'extras/inc/configcontext_format.html' %}
214
216
</ div >
215
217
< div class ="panel-body ">
216
- < pre > {{ configcontext.data|render_json }} </ pre >
218
+ {% include 'extras/inc/configcontext_data.html' with data= configcontext.data %}
217
219
</ div >
218
220
</ div >
219
221
</ div >
220
222
</ div >
221
223
{% endblock %}
224
+
225
+ {% block javascript %}
226
+ < script src ="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }} "> </ script >
227
+ {% endblock %}
Original file line number Diff line number Diff line change
1
+ {% load helpers %}
2
+
3
+ < div class ="rendered-context-data " data-format ="json ">
4
+ < pre > {{ data|render_json }}</ pre >
5
+ </ div >
6
+ < div class ="rendered-context-data " data-format ="yaml " style ="display: none; ">
7
+ < pre > {{ data|render_yaml }}</ pre >
8
+ </ div >
Original file line number Diff line number Diff line change
1
+ < div class ="pull-right ">
2
+ < div class ="btn-group btn-group-xs " role ="group ">
3
+ < span class ="btn btn-default rendered-context-format active " data-format ="json "> JSON</ span >
4
+ < span class ="btn btn-default rendered-context-format " data-format ="yaml "> YAML</ span >
5
+ </ div >
6
+ </ div >
Original file line number Diff line number Diff line change 1
1
{% extends base_template %}
2
2
{% load helpers %}
3
+ {% load static %}
3
4
4
5
{% block title %}{{ block.super }} - Config Context{% endblock %}
5
6
9
10
< div class ="panel panel-default ">
10
11
< div class ="panel-heading ">
11
12
< strong > Rendered Context</ strong >
13
+ {% include 'extras/inc/configcontext_format.html' %}
12
14
</ div >
13
15
< div class ="panel-body ">
14
- < pre > {{ rendered_context|render_json }} </ pre >
16
+ {% include 'extras/inc/configcontext_data.html' with data= rendered_context %}
15
17
</ div >
16
18
</ div >
17
19
</ div >
22
24
</ div >
23
25
< div class ="panel-body ">
24
26
{% if obj.local_context_data %}
25
- < pre > {{ obj.local_context_data|render_json }} </ pre >
27
+ {% include 'extras/inc/configcontext_data.html' with data= obj.local_context_data %}
26
28
{% else %}
27
29
< span class ="text-muted "> None</ span >
28
30
{% endif %}
47
49
{% if context.description %}
48
50
< br /> < small > {{ context.description }}</ small >
49
51
{% endif %}
50
- < pre > {{ context.data|render_json }} </ pre >
52
+ {% include 'extras/inc/configcontext_data.html' with data= context.data %}
51
53
</ div >
52
54
{% empty %}
53
55
< div class ="panel-body ">
58
60
</ div >
59
61
</ div >
60
62
{% endblock %}
63
+
64
+ {% block javascript %}
65
+ < script src ="{% static 'js/configcontext.js' %}?v{{ settings.VERSION }} "> </ script >
66
+ {% endblock %}
Original file line number Diff line number Diff line change 1
1
import datetime
2
2
import json
3
3
import re
4
+ import yaml
4
5
5
6
from django import template
6
7
from django .utils .html import strip_tags
@@ -76,6 +77,14 @@ def render_json(value):
76
77
return json .dumps (value , indent = 4 , sort_keys = True )
77
78
78
79
80
+ @register .filter ()
81
+ def render_yaml (value ):
82
+ """
83
+ Render a dictionary as formatted YAML.
84
+ """
85
+ return yaml .dump (dict (value ))
86
+
87
+
79
88
@register .filter ()
80
89
def model_name (obj ):
81
90
"""
You can’t perform that action at this time.
0 commit comments