diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 7a522f4563..67296cf284 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -119,11 +119,11 @@ class BaseForm(StrAndUnicode): bf_errors = ErrorList([escape(error) for error in bf.errors]) # Escape and cache in local variable. if bf.is_hidden: if bf_errors: - top_errors.extend(['(Hidden field %s) %s' % (name, e) for e in bf_errors]) + top_errors.extend(['(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors]) hidden_fields.append(unicode(bf)) else: if errors_on_separate_row and bf_errors: - output.append(error_row % bf_errors) + output.append(error_row % force_unicode(bf_errors)) if bf.label: label = escape(force_unicode(bf.label)) # Only add a colon if the label does not end in punctuation. @@ -133,10 +133,10 @@ class BaseForm(StrAndUnicode): else: label = '' if field.help_text: - help_text = help_text_html % field.help_text + help_text = help_text_html % force_unicode(field.help_text) else: help_text = u'' - output.append(normal_row % {'errors': bf_errors, 'label': label, 'field': unicode(bf), 'help_text': help_text}) + output.append(normal_row % {'errors': bf_errors, 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text}) if top_errors: output.insert(0, error_row % top_errors) if hidden_fields: # Insert any hidden fields in the last row. diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py index 1c85a5cf11..ae17d753bf 100644 --- a/django/newforms/widgets.py +++ b/django/newforms/widgets.py @@ -11,7 +11,7 @@ from itertools import chain from django.utils.datastructures import MultiValueDict from django.utils.html import escape from django.utils.translation import ugettext -from django.utils.encoding import StrAndUnicode, smart_unicode +from django.utils.encoding import StrAndUnicode, force_unicode from util import flatatt @@ -78,7 +78,7 @@ class Input(Widget): def render(self, name, value, attrs=None): if value is None: value = '' final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) - if value != '': final_attrs['value'] = smart_unicode(value) # Only add the 'value' attribute if a value is non-empty. + if value != '': final_attrs['value'] = force_unicode(value) # Only add the 'value' attribute if a value is non-empty. return u'' % flatatt(final_attrs) class TextInput(Input): @@ -112,7 +112,7 @@ class MultipleHiddenInput(HiddenInput): def render(self, name, value, attrs=None, choices=()): if value is None: value = [] final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) - return u'\n'.join([(u'' % flatatt(dict(value=smart_unicode(v), **final_attrs))) for v in value]) + return u'\n'.join([(u'' % flatatt(dict(value=force_unicode(v), **final_attrs))) for v in value]) def value_from_datadict(self, data, name): if isinstance(data, MultiValueDict): @@ -131,7 +131,7 @@ class Textarea(Widget): def render(self, name, value, attrs=None): if value is None: value = '' - value = smart_unicode(value) + value = force_unicode(value) final_attrs = self.build_attrs(attrs, name=name) return u'' % (flatatt(final_attrs), escape(value)) @@ -151,7 +151,7 @@ class CheckboxInput(Widget): if result: final_attrs['checked'] = 'checked' if value not in ('', True, False, None): - final_attrs['value'] = smart_unicode(value) # Only add the 'value' attribute if a value is non-empty. + final_attrs['value'] = force_unicode(value) # Only add the 'value' attribute if a value is non-empty. return u'' % flatatt(final_attrs) class Select(Widget): @@ -166,11 +166,11 @@ class Select(Widget): if value is None: value = '' final_attrs = self.build_attrs(attrs, name=name) output = [u'') return u'\n'.join(output) @@ -203,11 +203,11 @@ class SelectMultiple(Widget): if value is None: value = [] final_attrs = self.build_attrs(attrs, name=name) output = [u'') return u'\n'.join(output) @@ -221,8 +221,8 @@ class RadioInput(StrAndUnicode): def __init__(self, name, value, attrs, choice, index): self.name, self.value = name, value self.attrs = attrs - self.choice_value = smart_unicode(choice[0]) - self.choice_label = smart_unicode(choice[1]) + self.choice_value = force_unicode(choice[0]) + self.choice_label = force_unicode(choice[1]) self.index = index def __unicode__(self): @@ -255,13 +255,13 @@ class RadioFieldRenderer(StrAndUnicode): def __unicode__(self): "Outputs a