1
0
mirror of https://github.com/django/django.git synced 2025-10-27 23:56:08 +00:00

[py3] Refactored __unicode__ to __str__.

* Renamed the __unicode__ methods
* Applied the python_2_unicode_compatible decorator
* Removed the StrAndUnicode mix-in that is superseded by
  python_2_unicode_compatible
* Kept the __unicode__ methods in classes that specifically
  test it under Python 2
This commit is contained in:
Aymeric Augustin
2012-08-12 12:32:08 +02:00
parent 79d62a7175
commit d4a0b27838
142 changed files with 1072 additions and 481 deletions

View File

@@ -17,7 +17,7 @@ from django.forms.util import flatatt, to_current_timezone
from django.utils.datastructures import MultiValueDict, MergeDict
from django.utils.html import conditional_escape, format_html, format_html_join
from django.utils.translation import ugettext, ugettext_lazy
from django.utils.encoding import StrAndUnicode, force_text
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils import datetime_safe, formats
@@ -34,7 +34,8 @@ __all__ = (
MEDIA_TYPES = ('css','js')
class Media(StrAndUnicode):
@python_2_unicode_compatible
class Media(object):
def __init__(self, media=None, **kwargs):
if media:
media_attrs = media.__dict__
@@ -51,7 +52,7 @@ class Media(StrAndUnicode):
# if media_attrs != {}:
# raise TypeError("'class Media' has invalid attribute(s): %s" % ','.join(media_attrs.keys()))
def __unicode__(self):
def __str__(self):
return self.render()
def render(self):
@@ -142,7 +143,8 @@ class MediaDefiningClass(type):
new_class.media = media_property(new_class)
return new_class
class SubWidget(StrAndUnicode):
@python_2_unicode_compatible
class SubWidget(object):
"""
Some widgets are made of multiple HTML elements -- namely, RadioSelect.
This is a class that represents the "inner" HTML element of a widget.
@@ -152,7 +154,7 @@ class SubWidget(StrAndUnicode):
self.name, self.value = name, value
self.attrs, self.choices = attrs, choices
def __unicode__(self):
def __str__(self):
args = [self.name, self.value, self.attrs]
if self.choices:
args.append(self.choices)
@@ -647,6 +649,7 @@ class SelectMultiple(Select):
data_set = set([force_text(value) for value in data])
return data_set != initial_set
@python_2_unicode_compatible
class RadioInput(SubWidget):
"""
An object used by RadioFieldRenderer that represents a single
@@ -660,7 +663,7 @@ class RadioInput(SubWidget):
self.choice_label = force_text(choice[1])
self.index = index
def __unicode__(self):
def __str__(self):
return self.render()
def render(self, name=None, value=None, attrs=None, choices=()):
@@ -685,7 +688,8 @@ class RadioInput(SubWidget):
final_attrs['checked'] = 'checked'
return format_html('<input{0} />', flatatt(final_attrs))
class RadioFieldRenderer(StrAndUnicode):
@python_2_unicode_compatible
class RadioFieldRenderer(object):
"""
An object used by RadioSelect to enable customization of radio widgets.
"""
@@ -702,7 +706,7 @@ class RadioFieldRenderer(StrAndUnicode):
choice = self.choices[idx] # Let the IndexError propogate
return RadioInput(self.name, self.value, self.attrs.copy(), choice, idx)
def __unicode__(self):
def __str__(self):
return self.render()
def render(self):