Ticket #18063: no-unicode-in-repr.diff
File no-unicode-in-repr.diff, 1.5 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/model_regress/tests.py
1 # coding: utf-8 1 2 from __future__ import absolute_import 2 3 3 4 import datetime … … 145 146 # Models with broken unicode methods should still have a printable repr 146 147 b = BrokenUnicodeMethod.objects.create(name="Jerry") 147 148 self.assertEqual(repr(b), "<BrokenUnicodeMethod: [Bad Unicode data]>") 148 149 150 def test_no_unicode_in_repr(self): 151 a = Article.objects.create( 152 headline=u"Watch for umlauts: üöä", pub_date=datetime.datetime.now()) 153 self.assertEqual(repr(a), '<Article: Watch for umlauts: ???>') 154 149 155 @skipUnlessDBFeature("supports_timezones") 150 156 def test_timezones(self): 151 157 # Saving an updating with timezone-aware datetime Python objects. -
django/db/models/base.py
373 373 u = unicode(self) 374 374 except (UnicodeEncodeError, UnicodeDecodeError): 375 375 u = '[Bad Unicode data]' 376 return smart_str(u'<%s: %s>' % (self.__class__.__name__, u ))376 return smart_str(u'<%s: %s>' % (self.__class__.__name__, u.encode('ascii', 'replace'))) 377 377 378 378 def __str__(self): 379 379 if hasattr(self, '__unicode__'):