mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +00:00
Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible.
Thanks jpic for the report and chmodas for working on a patch.
Reverts 2ea80b94. Refs #19362.
This commit is contained in:
@@ -28,6 +28,10 @@ def python_2_unicode_compatible(klass):
|
||||
returning text and apply this decorator to the class.
|
||||
"""
|
||||
if six.PY2:
|
||||
if '__str__' not in klass.__dict__:
|
||||
raise ValueError("@python_2_unicode_compatible cannot be applied "
|
||||
"to %s because it doesn't define __str__()." %
|
||||
klass.__name__)
|
||||
klass.__unicode__ = klass.__str__
|
||||
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
|
||||
return klass
|
||||
|
||||
Reference in New Issue
Block a user