Django

Code

Changeset 5487

Show
Ignore:
Timestamp:
06/17/07 05:25:48 (1 year ago)
Author:
mtredinnick
Message:

unicode: Render templates as unicode objects and only convert them to
bytestrings as part of HttpRespnose? and other output paths.

Files:

Legend:

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

    r5277 r5487  
    33from django.contrib.sites.models import Site 
    44from django.core import urlresolvers 
     5from django.utils.encoding import smart_str 
    56 
    67def index(request, sitemaps): 
     
    2728        else: 
    2829            urls.extend(site.get_urls()) 
    29     xml = loader.render_to_string('sitemap.xml', {'urlset': urls}, encoding='utf-8'
     30    xml = smart_str(loader.render_to_string('sitemap.xml', {'urlset': urls})
    3031    return HttpResponse(xml, mimetype='application/xml') 
  • django/branches/unicode/django/http/__init__.py

    r5464 r5487  
    272272 
    273273    def _get_content(self): 
    274         content = ''.join(self._container) 
    275         if isinstance(content, unicode): 
    276             content = content.encode(self._charset) 
     274        content = smart_str(''.join(self._container), self._charset) 
    277275        return content 
    278276 
  • django/branches/unicode/django/template/__init__.py

    r5337 r5487  
    6161from django.utils.functional import curry, Promise 
    6262from django.utils.text import smart_split 
    63 from django.utils.encoding import smart_unicode, smart_str, force_unicode 
     63from django.utils.encoding import smart_unicode, force_unicode 
    6464from django.utils.translation import ugettext as _ 
    6565 
     
    177177                yield subnode 
    178178 
    179     def render(self, context, encoding=None): 
     179    def render(self, context): 
    180180        "Display stage -- can be called many times" 
    181         return self.nodelist.render(context, encoding
     181        return self.nodelist.render(context
    182182 
    183183def compile_string(template_string, origin): 
     
    733733 
    734734class NodeList(list): 
    735     # How invalid encoding sequences are handled. The default 'strict' is not 
    736     # appropriate, because the framework is not in control of all the string 
    737     # data. 
    738     codec_errors = 'replace' 
    739  
    740     def render(self, context, encoding=None): 
    741         if encoding is None: 
    742             encoding = settings.DEFAULT_CHARSET 
     735    def render(self, context): 
    743736        bits = [] 
    744737        for node in self: 
     
    747740            else: 
    748741                bits.append(node) 
    749         return ''.join([smart_str(b, encoding, errors=self.codec_errors) for b in bits]) 
     742        return ''.join([force_unicode(b) for b in bits]) 
    750743 
    751744    def get_nodes_by_type(self, nodetype): 
  • django/branches/unicode/django/template/loader.py

    r5277 r5487  
    8888    return Template(source, origin, name) 
    8989 
    90 def render_to_string(template_name, dictionary=None, context_instance=None, encoding=None): 
     90def render_to_string(template_name, dictionary=None, context_instance=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, encoding
     106    return t.render(context_instance
    107107 
    108108def select_template(template_name_list): 
  • django/branches/unicode/django/test/utils.py

    r5381 r5487  
    1111TEST_DATABASE_PREFIX = 'test_' 
    1212 
    13 def instrumented_test_render(self, context, unused=None): 
     13def instrumented_test_render(self, context): 
    1414    """ 
    1515    An instrumented Template render method, providing a signal 
  • django/branches/unicode/tests/regressiontests/forms/tests.py

    r5381 r5487  
    33593359</form> 
    33603360>>> Template('{{ form.password1.help_text }}').render(Context({'form': UserRegistration(auto_id=False)})) 
    3361 '' 
     3361u'' 
    33623362 
    33633363The label_tag() method takes an optional attrs argument: a dictionary of HTML 
  • django/branches/unicode/tests/regressiontests/templates/tests.py

    r5444 r5487  
    224224            # Make sure that any unicode strings are converted to bytestrings 
    225225            # in the final output. 
    226             'filter-syntax18': (r'{{ var }}', {'var': UTF8Class()}, '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'), 
     226            'filter-syntax18': (r'{{ var }}', {'var': UTF8Class()}, u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'), 
    227227 
    228228            ### COMMENT SYNTAX ######################################################## 
  • django/branches/unicode/tests/regressiontests/templates/unicode.py

    r5198 r5487  
    2525 
    2626Since both templates and all four contexts represent the same thing, they all 
    27 render the same (and are returned as bytestrings). 
     27render the same (and are returned as unicode objects). 
    2828 
    2929>>> t1.render(c3) == t2.render(c3) 
    3030True 
    3131>>> type(t1.render(c3)) 
    32 <type 'str'> 
     32<type 'unicode'> 
    3333"""