diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-12 12:32:08 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-12 14:44:40 +0200 |
| commit | d4a0b27838c815af87698920cc4db7d2afd6f05b (patch) | |
| tree | 6fedc7203389ab1f80f8cc7e913230c51e9b8776 /django/forms/widgets.py | |
| parent | 79d62a71751140315227891bbe175630f9d3edc3 (diff) | |
[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
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index be9ac8eb8f..fe7c06ff34 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -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): |
