diff --git a/django/db/models/base.py b/django/db/models/base.py
index 645ee7eb95..99e57e44c6 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -84,7 +84,7 @@ class Model(object):
return getattr(self, self._meta.pk.attname)
def __repr__(self):
- return smart_str(u'<%s: %s>' % (self.__class__.__name__, self))
+ return smart_str(u'<%s: %s>' % (self.__class__.__name__, unicode(self)))
def __str__(self):
if hasattr(self, '__unicode__'):
diff --git a/django/newforms/util.py b/django/newforms/util.py
index 5fc0223f5b..fae2c860a9 100644
--- a/django/newforms/util.py
+++ b/django/newforms/util.py
@@ -18,10 +18,10 @@ class ErrorDict(dict):
def as_ul(self):
if not self: return u''
- return u'
' % ''.join([u'%s%s' % (k, v) for k, v in self.items()])
+ return u'' % ''.join([u'%s%s' % (k, smart_unicode(v)) for k, v in self.items()])
def as_text(self):
- return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u' * %s' % i for i in v])) for k, v in self.items()])
+ return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u' * %s' % smart_unicode(i) for i in v])) for k, v in self.items()])
class ErrorList(list):
"""
@@ -32,11 +32,11 @@ class ErrorList(list):
def as_ul(self):
if not self: return u''
- return u'' % ''.join([u'%s' % e for e in self])
+ return u'' % ''.join([u'%s' % smart_unicode(e) for e in self])
def as_text(self):
if not self: return u''
- return u'\n'.join([u'* %s' % e for e in self])
+ return u'\n'.join([u'* %s' % smart_unicode(e) for e in self])
class ValidationError(Exception):
def __init__(self, message):
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index dd71ebc455..a726ebf894 100644
--- a/django/newforms/widgets.py
+++ b/django/newforms/widgets.py
@@ -253,7 +253,7 @@ class RadioFieldRenderer(StrAndUnicode):
def __unicode__(self):
"Outputs a for this set of radio fields."
- return u'' % u'\n'.join([u'- %s
' % w for w in self])
+ return u'' % u'\n'.join([u'- %s
' % smart_unicode(w) for w in self])
class RadioSelect(Select):
def render(self, name, value, attrs=None, choices=()):
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index f6835893c9..1a1c5b96fe 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -170,7 +170,7 @@ upper = stringfilter(upper)
def urlencode(value):
"Escapes a value for use in a URL"
import urllib
- return urllib.quote(value).decode('utf-8')
+ return smart_unicode(urllib.quote(value))
urlencode = stringfilter(urlencode)
def urlize(value):
@@ -364,10 +364,10 @@ def unordered_list(value):
def _helper(value, tabs):
indent = u'\t' * tabs
if value[1]:
- return u'%s- %s\n%s\n%s
' % (indent, value[0], indent,
+ return u'%s- %s\n%s\n%s
' % (indent, smart_unicode(value[0]), indent,
u'\n'.join([_helper(v, tabs+1) for v in value[1]]), indent, indent)
else:
- return u'%s- %s
' % (indent, value[0])
+ return u'%s- %s
' % (indent, smart_unicode(value[0]))
return _helper(value, 1)
###################
@@ -546,7 +546,7 @@ def pprint(value):
try:
return pformat(value)
except Exception, e:
- return u"Error in formatting:%s" % e
+ return u"Error in formatting:%s" % smart_unicode(e)
# Syntax: register.filter(name of filter, callback)
register.filter(add)
diff --git a/django/utils/html.py b/django/utils/html.py
index efb8b5a154..44c2809b42 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -32,7 +32,7 @@ def linebreaks(value):
"Converts newlines into and
s"
value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
paras = re.split('\n{2,}', value)
- paras = ['
%s
' % p.strip().replace('\n', '
') for p in paras]
+ paras = [u'%s
' % p.strip().replace('\n', '
') for p in paras]
return u'\n\n'.join(paras)
def strip_tags(value):
@@ -53,14 +53,16 @@ def fix_ampersands(value):
def urlize(text, trim_url_limit=None, nofollow=False):
"""
- Converts any URLs in text into clickable links. Works on http://, https:// and
- www. links. Links can have trailing punctuation (periods, commas, close-parens)
- and leading punctuation (opening parens) and it'll still do the right thing.
+ Converts any URLs in text into clickable links. Works on http://, https://
+ and www. links. Links can have trailing punctuation (periods, commas,
+ close-parens) and leading punctuation (opening parens) and it'll still do
+ the right thing.
If trim_url_limit is not None, the URLs in link text will be limited to
trim_url_limit characters.
- If nofollow is True, the URLs in link text will get a rel="nofollow" attribute.
+ If nofollow is True, the URLs in link text will get a rel="nofollow"
+ attribute.
"""
trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or '')) or x
words = word_split_re.split(text)