Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

unicode: Added (optional) explicit template encoding specification. A…

…lso ported

contrib.sitemaps over (we want to ensure the output XML is in a valid encoding,
so we force UTF-8 in this case).


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 52b0051523cb6608bf401aff9a42bc88567606cc 1 parent a8404e6
Malcolm Tredinnick authored May 17, 2007
2  django/contrib/sitemaps/views.py
@@ -26,5 +26,5 @@ def sitemap(request, sitemaps, section=None):
26 26
             urls.extend(site().get_urls())
27 27
         else:
28 28
             urls.extend(site.get_urls())
29  
-    xml = loader.render_to_string('sitemap.xml', {'urlset': urls})
  29
+    xml = loader.render_to_string('sitemap.xml', {'urlset': urls}, encoding='utf-8')
30 30
     return HttpResponse(xml, mimetype='application/xml')
9  django/template/__init__.py
@@ -176,9 +176,9 @@ def __iter__(self):
176 176
             for subnode in node:
177 177
                 yield subnode
178 178
 
179  
-    def render(self, context):
  179
+    def render(self, context, encoding=None):
180 180
         "Display stage -- can be called many times"
181  
-        return self.nodelist.render(context)
  181
+        return self.nodelist.render(context, encoding)
182 182
 
183 183
 def compile_string(template_string, origin):
184 184
     "Compiles template_string into NodeList ready for rendering"
@@ -730,14 +730,15 @@ class NodeList(list):
730 730
     # data.
731 731
     codec_errors = 'replace'
732 732
 
733  
-    def render(self, context):
  733
+    def render(self, context, encoding=None):
  734
+        if encoding is None:
  735
+            encoding = settings.DEFAULT_CHARSET
734 736
         bits = []
735 737
         for node in self:
736 738
             if isinstance(node, Node):
737 739
                 bits.append(self.render_node(node, context))
738 740
             else:
739 741
                 bits.append(node)
740  
-        encoding = settings.DEFAULT_CHARSET
741 742
         return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b in bits])
742 743
 
743 744
     def get_nodes_by_type(self, nodetype):
4  django/template/loader.py
@@ -87,7 +87,7 @@ def get_template_from_string(source, origin=None, name=None):
87 87
     """
88 88
     return Template(source, origin, name)
89 89
 
90  
-def render_to_string(template_name, dictionary=None, context_instance=None):
  90
+def render_to_string(template_name, dictionary=None, context_instance=None, encoding=None):
91 91
     """
92 92
     Loads the given template_name and renders it with the given dictionary as
93 93
     context. The template_name may be a string to load a single template using
@@ -103,7 +103,7 @@ def render_to_string(template_name, dictionary=None, context_instance=None):
103 103
         context_instance.update(dictionary)
104 104
     else:
105 105
         context_instance = Context(dictionary)
106  
-    return t.render(context_instance)
  106
+    return t.render(context_instance, encoding)
107 107
 
108 108
 def select_template(template_name_list):
109 109
     "Given a list of template names, returns the first that can be loaded."
6  django/test/utils.py
@@ -10,10 +10,10 @@
10 10
 # the test database.
11 11
 TEST_DATABASE_PREFIX = 'test_'
12 12
 
13  
-def instrumented_test_render(self, context):
14  
-    """An instrumented Template render method, providing a signal 
  13
+def instrumented_test_render(self, context, unused=None):
  14
+    """
  15
+    An instrumented Template render method, providing a signal
15 16
     that can be intercepted by the test system Client
16  
-    
17 17
     """
18 18
     dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)
19 19
     return self.nodelist.render(context)

0 notes on commit 52b0051

Please sign in to comment.
Something went wrong with that request. Please try again.