Skip to content

Commit c851717

Browse files
author
Brian Luft
committed
Merge pull request #3 from graingert/patch-2
use mark_safe for json output
2 parents 54e4b16 + 5b2aa8b commit c851717

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ it in a Django template::
2626

2727
<script id="source" language="javascript" type="text/javascript">
2828
$(function () {
29-
$.plot($("#linear-graph"), {{ graph.series_json|safe }}, {{ graph.options_json|safe }});
29+
$.plot($("#linear-graph"), {{ graph.series_json }}, {{ graph.options_json }});
3030
});
3131
</script>
3232

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ it in a Django template:
3333
<div id="linear-graph" style="width:600px;height:400px"></div>
3434
<script id="source" language="javascript" type="text/javascript">
3535
$(function () {
36-
$.plot($("#linear-graph"), {{ graph.series_json|safe }}, {{ graph.options_json|safe }});
36+
$.plot($("#linear-graph"), {{ graph.series_json }}, {{ graph.options_json }});
3737
});
3838
</script>
3939

pyflot/graph.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import inspect
1616
import json
1717
import time
18+
from django.utils.safestring import mark_safe
1819

1920

2021
__title__ = 'pyflot'
@@ -23,6 +24,9 @@
2324
__license__ = 'MIT'
2425
__copyright__ = 'Copyright 2011 Brian Luft'
2526

27+
def safe_json(obj):
28+
return mark_safe(json.dumps(obj))
29+
2630

2731
def update(d, u):
2832
"""
@@ -84,7 +88,7 @@ def series_json(self):
8488
associated with this graph formatted as JSON,
8589
suitable for passing to the ``$.plot`` method.
8690
"""
87-
return json.dumps([self.prepare_series(s) for s in self._series])
91+
return safe_json([self.prepare_series(s) for s in self._series])
8892

8993
@property
9094
def options_json(self):
@@ -93,7 +97,7 @@ def options_json(self):
9397
for this graph in a format suitable for passing to
9498
the ``$.plot`` method as the options parameter.
9599
"""
96-
return json.dumps(self._options)
100+
return safe_json(self._options)
97101

98102
def __getattr__(self, value):
99103
"""

pyflot/templates/test_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<script type="text/javascript" src="pyflot/templates/jquery.flot.min.js"></script>
1010
<script type="text/javascript">
1111
$(function () {
12-
$.plot($("#testgraph"), {{ graph.series_json|safe }}, {{ graph.options_json|safe }});
12+
$.plot($("#testgraph"), {{ graph.series_json }}, {{ graph.options_json }});
1313
});
1414
</script>
1515
</head>

0 commit comments

Comments
 (0)