Author: adrian
Date: 2007-02-14 22:13:02 -0600 (Wed, 14 Feb 2007)
New Revision: 4522

Modified:
   django/trunk/django/newforms/util.py
   django/trunk/tests/regressiontests/forms/tests.py
Log:
Fixed #3314 -- Fixed a bug in newforms smart_unicode. Thanks for the patch, nesh

Modified: django/trunk/django/newforms/util.py
===================================================================
--- django/trunk/django/newforms/util.py        2007-02-15 04:03:47 UTC (rev 
4521)
+++ django/trunk/django/newforms/util.py        2007-02-15 04:13:02 UTC (rev 
4522)
@@ -7,7 +7,10 @@
 
 def smart_unicode(s):
     if not isinstance(s, basestring):
-        s = unicode(str(s))
+        if hasattr(s, '__unicode__'):
+            s = unicode(s)
+        else:
+            s = unicode(str(s), settings.DEFAULT_CHARSET)
     elif not isinstance(s, unicode):
         s = unicode(s, settings.DEFAULT_CHARSET)
     return s

Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py   2007-02-15 04:03:47 UTC 
(rev 4521)
+++ django/trunk/tests/regressiontests/forms/tests.py   2007-02-15 04:13:02 UTC 
(rev 4522)
@@ -3265,6 +3265,29 @@
 u''
 >>> f.clean('')
 u''
+
+#################################
+# Tests of underlying functions #
+#################################
+
+# smart_unicode tests
+>>> from django.newforms.util import smart_unicode
+>>> class Test:
+...     def __str__(self):
+...        return 'ŠĐĆŽćžšđ'
+>>> class TestU:
+...     def __str__(self):
+...        return 'Foo'
+...     def __unicode__(self):
+...        return u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(Test())
+u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(TestU())
+u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(1)
+u'1'
+>>> smart_unicode('foo')
+u'foo'
 """
 
 if __name__ == "__main__":


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to