Navigation Menu

Skip to content

Commit

Permalink
Make autoescape an option:
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Dec 31, 2010
1 parent f12cd71 commit 3ba5c42
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/config.html
Expand Up @@ -129,6 +129,8 @@ <h3 id="planet"><code>[planet]</code></h3>
<dt><ins>pubsubhubbub_feeds</ins></dt>
<dd>List of feeds to publish. Defaults to <code>atom.xml rss10.xml
rss20.xml</code>.</dd>
<dt id="django_autoescape"><ins>django_autoescape</ins></dt>
<dd>Control <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape">autoescaping</a> behavior of django templates. Defaults to <code>on</code>.</dd>
</dl>
<p>Additional options can be found in
<a href="normalization.html#overrides">normalization level overrides</a>.</p>
Expand Down
6 changes: 6 additions & 0 deletions docs/templates.html
Expand Up @@ -143,6 +143,12 @@ <h3>django</h3>
requires at least Python 2.3.
</p>

<p>
The <a href="config.html#django_autoescape">django_autoescape</a> config
option may be used to globally set the default value for
<a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape">auto-escaping</a>.
</p>

<h3>xslt</h3>
<p><a href="http://www.w3.org/TR/xslt">XSLT</a> is a paradox: it actually
makes some simple things easier to do than htmltmpl, and certainly can
Expand Down
1 change: 1 addition & 0 deletions planet/config.py
Expand Up @@ -116,6 +116,7 @@ def define_tmpl_int(name, default):
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)
Expand Down
2 changes: 1 addition & 1 deletion planet/shell/dj.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/data/filter/django/test.xml
Expand Up @@ -10,7 +10,7 @@
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>

<entry>
<title>&#161;Atom-Powered Robots Run Amok!</title>
<title type='xhtml'>&#161;Atom-Powered <b>Robots</b> Run Amok!</title>
<link href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
Expand Down
12 changes: 11 additions & 1 deletion tests/test_filter_django.py
Expand Up @@ -24,7 +24,17 @@ def test_django_entry_title(self):
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 &lt;b&gt;Robots&lt;/b&gt; 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 <b>Robots</b> Run Amok!\n")

def test_django_config_context(self):
config.load('tests/data/filter/django/test.ini')
Expand Down
6 changes: 3 additions & 3 deletions themes/django/index.html.dj
Expand Up @@ -21,7 +21,7 @@

<ul>
{% for channel in Channels %}
<li>{{ channel.title }} by {{ channel.author_name }}</li>
<li>{{ channel.title|safe }} by {{ channel.author_name }}</li>
{% endfor %}
</ul>
</div>
Expand All @@ -32,9 +32,9 @@
{% endifchanged %}

<div class="entry">
{% if item.title %}<h4>{{ item.title }}</h4>{% endif %}
{% if item.title %}<h4>{{ item.title|safe }}</h4>{% endif %}

{{ item.content }}
{{ item.content|safe }}

<p class="entry-tools">
by {{ item.channel_author }} on
Expand Down

0 comments on commit 3ba5c42

Please sign in to comment.