Added, tested and documented the new Config variable available in the Django templates/filters: makes it easy to access .ini configuration items from one's templates

This commit is contained in:
Antonio Cavedoni 2007-03-01 20:37:02 +01:00
parent a590d13fe8
commit fb29d39501
4 changed files with 16 additions and 0 deletions

View File

@ -115,6 +115,11 @@ Item.</p>
able to iterate through them.
</p>
<p>
You also have access to the <code>Config</code> dictionary, which contains
the Venus configuration variables from your <code>.ini</code> file.
</p>
<p>
If you lose your way and want to introspect all the variable in the
context, there's the useful <code>{% debug %}</code> template tag.

View File

@ -33,6 +33,7 @@ def run(script, doc, output_file=None, options={}):
# datatype converters
context = Context()
context.update(tmpl.template_info(doc))
context['Config'] = config.planet_options()
t = get_template(script)
if output_file:

View File

@ -0,0 +1 @@
{{ Config.name }}

View File

@ -26,6 +26,15 @@ class DjangoFilterTests(unittest.TestCase):
os.path.realpath('tests/data/filter/django/title.html.dj'), input)
self.assertEqual(results, "Atom-Powered Robots Run Amok\n")
def test_django_config_context(self):
config.load('tests/data/filter/django/test.ini')
feed = open('tests/data/filter/django/test.xml')
input = feed.read(); feed.close()
results = dj.run(
os.path.realpath('tests/data/filter/django/config.html.dj'), input)
self.assertEqual(results, "Django on Venus\n")
try:
from django.conf import settings
except ImportError: