Django

Code

Changeset 5277

Show
Ignore:
Timestamp:
05/17/07 11:55:38 (1 year ago)
Author:
mtredinnick
Message:

unicode: Added (optional) explicit template encoding specification. Also ported
contrib.sitemaps over (we want to ensure the output XML is in a valid encoding,
so we force UTF-8 in this case).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/contrib/sitemaps/views.py

    r5126 r5277  
    2727        else: 
    2828            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'
    3030    return HttpResponse(xml, mimetype='application/xml') 
  • django/branches/unicode/django/template/__init__.py

    r5230 r5277  
    177177                yield subnode 
    178178 
    179     def render(self, context): 
     179    def render(self, context, encoding=None): 
    180180        "Display stage -- can be called many times" 
    181         return self.nodelist.render(context
     181        return self.nodelist.render(context, encoding
    182182 
    183183def compile_string(template_string, origin): 
     
    731731    codec_errors = 'replace' 
    732732 
    733     def render(self, context): 
     733    def render(self, context, encoding=None): 
     734        if encoding is None: 
     735            encoding = settings.DEFAULT_CHARSET 
    734736        bits = [] 
    735737        for node in self: 
     
    738740            else: 
    739741                bits.append(node) 
    740         encoding = settings.DEFAULT_CHARSET 
    741742        return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b in bits]) 
    742743 
  • django/branches/unicode/django/template/loader.py

    r4265 r5277  
    8888    return Template(source, origin, name) 
    8989 
    90 def render_to_string(template_name, dictionary=None, context_instance=None): 
     90def render_to_string(template_name, dictionary=None, context_instance=None, encoding=None): 
    9191    """ 
    9292    Loads the given template_name and renders it with the given dictionary as 
     
    104104    else: 
    105105        context_instance = Context(dictionary) 
    106     return t.render(context_instance
     106    return t.render(context_instance, encoding
    107107 
    108108def select_template(template_name_list): 
  • django/branches/unicode/django/test/utils.py

    r5185 r5277  
    1111TEST_DATABASE_PREFIX = 'test_' 
    1212 
    13 def instrumented_test_render(self, context): 
    14     """An instrumented Template render method, providing a signal  
     13def instrumented_test_render(self, context, unused=None): 
     14    """ 
     15    An instrumented Template render method, providing a signal 
    1516    that can be intercepted by the test system Client 
    16      
    1717    """ 
    1818    dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)