summaryrefslogtreecommitdiff
path: root/django/template/loader.py
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
committerChristopher Long <indirecthit@gmail.com>2007-06-17 22:18:54 +0000
commitae22b6d403dcf25098c77f0dfcf59ae58b186461 (patch)
treec37fc631e99a7e4d909d6b6d236f495003731ea7 /django/template/loader.py
parent0cf7bc439129c66df8d64601e885f83b256b4f25 (diff)
per-object-permissions: Merged to trunk [5486] NOTE: Not fully tested, will be working on this over the next few weeks.
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@5488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template/loader.py')
-rw-r--r--django/template/loader.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/django/template/loader.py b/django/template/loader.py
index 03e6f8d49d..45cf5a9d7c 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -87,14 +87,12 @@ def get_template_from_string(source, origin=None, name=None):
"""
return Template(source, origin, name)
-def render_to_string(template_name, dictionary=None, context_instance=None):
+def _render_setup(template_name, dictionary=None, context_instance=None):
"""
- Loads the given template_name and renders it with the given dictionary as
- context. The template_name may be a string to load a single template using
- get_template, or it may be a tuple to use select_template to find one of
- the templates in the list. Returns a string.
+ Common setup code for render_to_string and render_to_iter.
"""
- dictionary = dictionary or {}
+ if dictionary is None:
+ dictionary = {}
if isinstance(template_name, (list, tuple)):
t = select_template(template_name)
else:
@@ -103,7 +101,28 @@ def render_to_string(template_name, dictionary=None, context_instance=None):
context_instance.update(dictionary)
else:
context_instance = Context(dictionary)
- return t.render(context_instance)
+ return t, context_instance
+
+def render_to_string(template_name, dictionary=None, context_instance=None):
+ """
+ Loads the given template_name and renders it with the given dictionary as
+ context. The template_name may be a string to load a single template using
+ get_template, or it may be a tuple to use select_template to find one of
+ the templates in the list. Returns a string.
+ """
+ t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance)
+ return t.render(c)
+
+def render_to_iter(template_name, dictionary=None, context_instance=None):
+ """
+ Loads the given template_name and renders it with the given dictionary as
+ context. The template_name may be a string to load a single template using
+ get_template, or it may be a tuple to use select_template to find one of
+ the templates in the list. Returns a string.
+ """
+ t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance)
+ return t.iter_render(c)
+
def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded."