mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 19:52:52 -06:00
Introduced the render_json template filter
This commit is contained in:
parent
c13e4858d7
commit
b952ec73ce
@ -854,10 +854,6 @@ class ObjectChange(models.Model):
|
||||
self.object_data,
|
||||
)
|
||||
|
||||
@property
|
||||
def object_data_pretty(self):
|
||||
return json.dumps(self.object_data, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
#
|
||||
# User actions
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% extends 'dcim/device.html' %}
|
||||
{% load helpers %}
|
||||
|
||||
{% block title %}{{ device }} - Config Context{% endblock %}
|
||||
|
||||
@ -10,7 +11,7 @@
|
||||
<strong>Config Context</strong>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<pre>{{ device.get_config_context }}</pre>
|
||||
<pre>{{ device.get_config_context|render_json }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -83,7 +83,7 @@
|
||||
<strong>Object Data</strong>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<pre>{{ objectchange.object_data_pretty }}</pre>
|
||||
<pre>{{ objectchange.object_data|render_json }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
@ -46,6 +47,14 @@ def gfm(value):
|
||||
return mark_safe(html)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def render_json(value):
|
||||
"""
|
||||
Render a dictionary as formatted JSON.
|
||||
"""
|
||||
return json.dumps(value, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
@register.filter()
|
||||
def model_name(obj):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user