From 3ba5c4200be0b465e34108ed5d4dcba7a1e77d3d Mon Sep 17 00:00:00 2001
From: Sam Ruby
Date: Fri, 31 Dec 2010 10:20:58 -0500
Subject: [PATCH] Make autoescape an option:
http://lists.planetplanet.org/archives/devel/2010-December/002189.html
---
docs/config.html | 2 ++
docs/templates.html | 6 ++++++
planet/config.py | 1 +
planet/shell/dj.py | 2 +-
tests/data/filter/django/test.xml | 2 +-
tests/test_filter_django.py | 12 +++++++++++-
themes/django/index.html.dj | 6 +++---
7 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/docs/config.html b/docs/config.html
index 0e5d00c..ee6cf45 100644
--- a/docs/config.html
+++ b/docs/config.html
@@ -129,6 +129,8 @@ home page for more information.
pubsubhubbub_feeds
List of feeds to publish. Defaults to atom.xml rss10.xml
rss20.xml
.
+django_autoescape
+Control autoescaping behavior of django templates. Defaults to on
.
Additional options can be found in
normalization level overrides.
diff --git a/docs/templates.html b/docs/templates.html
index b9fd9c1..5549901 100644
--- a/docs/templates.html
+++ b/docs/templates.html
@@ -143,6 +143,12 @@ Item.
requires at least Python 2.3.
+
+ The django_autoescape config
+ option may be used to globally set the default value for
+ auto-escaping.
+
+
xslt
XSLT is a paradox: it actually
makes some simple things easier to do than htmltmpl, and certainly can
diff --git a/planet/config.py b/planet/config.py
index 176ee9d..d36899f 100644
--- a/planet/config.py
+++ b/planet/config.py
@@ -116,6 +116,7 @@ def __init__():
define_planet_list('bill_of_materials')
define_planet_list('template_directories', '.')
define_planet_list('filter_directories')
+ define_planet('django_autoescape', 'on')
# template options
define_tmpl_int('days_per_page', 0)
diff --git a/planet/shell/dj.py b/planet/shell/dj.py
index 96bcd3b..d2199fc 100644
--- a/planet/shell/dj.py
+++ b/planet/shell/dj.py
@@ -32,7 +32,7 @@ def run(script, doc, output_file=None, options={}):
# set up the Django context by using the default htmltmpl
# datatype converters
- context = Context()
+ context = Context(autoescape=(config.django_autoescape()=='on'))
context.update(tmpl.template_info(doc))
context['Config'] = config.planet_options()
t = get_template(script)
diff --git a/tests/data/filter/django/test.xml b/tests/data/filter/django/test.xml
index 323a3e8..1d9882a 100644
--- a/tests/data/filter/django/test.xml
+++ b/tests/data/filter/django/test.xml
@@ -10,7 +10,7 @@
urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
- ¡Atom-Powered Robots Run Amok!
+ ¡Atom-Powered Robots Run Amok!
urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
2003-12-13T18:30:02Z
diff --git a/tests/test_filter_django.py b/tests/test_filter_django.py
index d72800a..5be54a0 100644
--- a/tests/test_filter_django.py
+++ b/tests/test_filter_django.py
@@ -24,7 +24,17 @@ class DjangoFilterTests(unittest.TestCase):
input = feed.read(); feed.close()
results = dj.run(
os.path.realpath('tests/data/filter/django/title.html.dj'), input)
- self.assertEqual(results, u"\xa1Atom-Powered Robots Run Amok!\n")
+ self.assertEqual(results,
+ u"\xa1Atom-Powered <b>Robots</b> Run Amok!\n")
+
+ def test_django_entry_title_autoescape_off(self):
+ config.load('tests/data/filter/django/test.ini')
+ config.parser.set('Planet', 'django_autoescape', 'off')
+ feed = open('tests/data/filter/django/test.xml')
+ input = feed.read(); feed.close()
+ results = dj.run(
+ os.path.realpath('tests/data/filter/django/title.html.dj'), input)
+ self.assertEqual(results, u"\xa1Atom-Powered Robots Run Amok!\n")
def test_django_config_context(self):
config.load('tests/data/filter/django/test.ini')
diff --git a/themes/django/index.html.dj b/themes/django/index.html.dj
index 632a527..637e60d 100644
--- a/themes/django/index.html.dj
+++ b/themes/django/index.html.dj
@@ -21,7 +21,7 @@
{% for channel in Channels %}
- - {{ channel.title }} by {{ channel.author_name }}
+ - {{ channel.title|safe }} by {{ channel.author_name }}
{% endfor %}
@@ -32,9 +32,9 @@
{% endifchanged %}
- {% if item.title %}
{{ item.title }}
{% endif %}
+ {% if item.title %}
{{ item.title|safe }}
{% endif %}
- {{ item.content }}
+ {{ item.content|safe }}
by {{ item.channel_author }} on