Changeset 5487
- Timestamp:
- 06/17/07 05:25:48 (1 year ago)
- Files:
-
- django/branches/unicode/django/contrib/sitemaps/views.py (modified) (2 diffs)
- django/branches/unicode/django/http/__init__.py (modified) (1 diff)
- django/branches/unicode/django/template/__init__.py (modified) (4 diffs)
- django/branches/unicode/django/template/loader.py (modified) (2 diffs)
- django/branches/unicode/django/test/utils.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/forms/tests.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/templates/tests.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/templates/unicode.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode/django/contrib/sitemaps/views.py
r5277 r5487 3 3 from django.contrib.sites.models import Site 4 4 from django.core import urlresolvers 5 from django.utils.encoding import smart_str 5 6 6 7 def index(request, sitemaps): … … 27 28 else: 28 29 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})) 30 31 return HttpResponse(xml, mimetype='application/xml') django/branches/unicode/django/http/__init__.py
r5464 r5487 272 272 273 273 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) 277 275 return content 278 276 django/branches/unicode/django/template/__init__.py
r5337 r5487 61 61 from django.utils.functional import curry, Promise 62 62 from django.utils.text import smart_split 63 from django.utils.encoding import smart_unicode, smart_str,force_unicode63 from django.utils.encoding import smart_unicode, force_unicode 64 64 from django.utils.translation import ugettext as _ 65 65 … … 177 177 yield subnode 178 178 179 def render(self, context , encoding=None):179 def render(self, context): 180 180 "Display stage -- can be called many times" 181 return self.nodelist.render(context , encoding)181 return self.nodelist.render(context) 182 182 183 183 def compile_string(template_string, origin): … … 733 733 734 734 class 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): 743 736 bits = [] 744 737 for node in self: … … 747 740 else: 748 741 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]) 750 743 751 744 def get_nodes_by_type(self, nodetype): django/branches/unicode/django/template/loader.py
r5277 r5487 88 88 return Template(source, origin, name) 89 89 90 def render_to_string(template_name, dictionary=None, context_instance=None , encoding=None):90 def render_to_string(template_name, dictionary=None, context_instance=None): 91 91 """ 92 92 Loads the given template_name and renders it with the given dictionary as … … 104 104 else: 105 105 context_instance = Context(dictionary) 106 return t.render(context_instance , encoding)106 return t.render(context_instance) 107 107 108 108 def select_template(template_name_list): django/branches/unicode/django/test/utils.py
r5381 r5487 11 11 TEST_DATABASE_PREFIX = 'test_' 12 12 13 def instrumented_test_render(self, context , unused=None):13 def instrumented_test_render(self, context): 14 14 """ 15 15 An instrumented Template render method, providing a signal django/branches/unicode/tests/regressiontests/forms/tests.py
r5381 r5487 3359 3359 </form> 3360 3360 >>> Template('{{ form.password1.help_text }}').render(Context({'form': UserRegistration(auto_id=False)})) 3361 ''3361 u'' 3362 3362 3363 3363 The label_tag() method takes an optional attrs argument: a dictionary of HTML django/branches/unicode/tests/regressiontests/templates/tests.py
r5444 r5487 224 224 # Make sure that any unicode strings are converted to bytestrings 225 225 # 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'), 227 227 228 228 ### COMMENT SYNTAX ######################################################## django/branches/unicode/tests/regressiontests/templates/unicode.py
r5198 r5487 25 25 26 26 Since both templates and all four contexts represent the same thing, they all 27 render the same (and are returned as bytestrings).27 render the same (and are returned as unicode objects). 28 28 29 29 >>> t1.render(c3) == t2.render(c3) 30 30 True 31 31 >>> type(t1.render(c3)) 32 <type ' str'>32 <type 'unicode'> 33 33 """
