1
0
mirror of https://github.com/django/django.git synced 2025-10-25 06:36:07 +00:00

[py3] Replaced unicode/str by six.text_type/bytes.

This commit is contained in:
Aymeric Augustin
2012-07-20 14:48:51 +02:00
parent 3cb2457f46
commit bdca5ea345
96 changed files with 376 additions and 294 deletions

View File

@@ -331,10 +331,10 @@ class BaseTemporalField(Field):
def to_python(self, value):
# Try to coerce the value to unicode.
unicode_value = force_unicode(value, strings_only=True)
if isinstance(unicode_value, unicode):
if isinstance(unicode_value, six.text_type):
value = unicode_value.strip()
# If unicode, try to strptime against each input format.
if isinstance(value, unicode):
if isinstance(value, six.text_type):
for format in self.input_formats:
try:
return self.strptime(value, format)

View File

@@ -151,7 +151,7 @@ class BaseForm(StrAndUnicode):
if bf.is_hidden:
if bf_errors:
top_errors.extend(['(Hidden field %s) %s' % (name, force_unicode(e)) for e in bf_errors])
hidden_fields.append(unicode(bf))
hidden_fields.append(six.text_type(bf))
else:
# Create a 'class="..."' atribute if the row should have any
# CSS classes applied.
@@ -181,7 +181,7 @@ class BaseForm(StrAndUnicode):
output.append(normal_row % {
'errors': force_unicode(bf_errors),
'label': force_unicode(label),
'field': unicode(bf),
'field': six.text_type(bf),
'help_text': help_text,
'html_class_attr': html_class_attr
})

View File

@@ -7,6 +7,7 @@ from django.forms.util import ErrorList
from django.forms.widgets import Media, HiddenInput
from django.utils.encoding import StrAndUnicode
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.translation import ugettext as _
@@ -345,17 +346,17 @@ class BaseFormSet(StrAndUnicode):
# probably should be. It might make sense to render each form as a
# table row with each field as a td.
forms = ' '.join([form.as_table() for form in self])
return mark_safe('\n'.join([unicode(self.management_form), forms]))
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
def as_p(self):
"Returns this formset rendered as HTML <p>s."
forms = ' '.join([form.as_p() for form in self])
return mark_safe('\n'.join([unicode(self.management_form), forms]))
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
def as_ul(self):
"Returns this formset rendered as HTML <li>s."
forms = ' '.join([form.as_ul() for form in self])
return mark_safe('\n'.join([unicode(self.management_form), forms]))
return mark_safe('\n'.join([six.text_type(self.management_form), forms]))
def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
can_delete=False, max_num=None):

View File

@@ -576,7 +576,7 @@ class BaseModelFormSet(BaseFormSet):
else:
return ugettext("Please correct the duplicate data for %(field)s, "
"which must be unique.") % {
"field": get_text_list(unique_check, unicode(_("and"))),
"field": get_text_list(unique_check, six.text_type(_("and"))),
}
def get_date_error_message(self, date_check):
@@ -584,7 +584,7 @@ class BaseModelFormSet(BaseFormSet):
"which must be unique for the %(lookup)s in %(date_field)s.") % {
'field_name': date_check[2],
'date_field': date_check[3],
'lookup': unicode(date_check[1]),
'lookup': six.text_type(date_check[1]),
}
def get_form_error(self):