Switched form using smart_unicode to smart_text and force_unicode to force_text

This commit is contained in:
Brent O'Connor 2016-02-11 08:49:01 -06:00
parent 337cca5813
commit 93d97d805b
3 changed files with 13 additions and 13 deletions

View file

@ -3,12 +3,12 @@ from django.db import models
from django.template import Library
from django.contrib.admin.templatetags.admin_list import result_headers, _boolean_icon
try:
from django.contrib.admin.util import lookup_field, display_for_field, label_for_field
from django.contrib.admin.utils import lookup_field, display_for_field, label_for_field
except ImportError:
from categories.editor.utils import lookup_field, display_for_field, label_for_field
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
from django.core.exceptions import ObjectDoesNotExist
from django.utils.encoding import smart_unicode, force_unicode
from django.utils.encoding import smart_text, force_text
from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe
@ -44,7 +44,7 @@ def items_for_tree_result(cl, result, form):
allow_tags = True
result_repr = _boolean_icon(value)
else:
result_repr = smart_unicode(value)
result_repr = smart_text(value)
# Strip HTML tags in the resulting text, except if the
# function has an "allow_tags" attribute set to True.
if not allow_tags:
@ -71,7 +71,7 @@ def items_for_tree_result(cl, result, form):
except (AttributeError, ObjectDoesNotExist):
pass
if force_unicode(result_repr) == '':
if force_text(result_repr) == '':
result_repr = mark_safe(' ')
# If list_display_links not defined, add the link tag to the first field
if (first and not cl.list_display_links) or field_name in cl.list_display_links:
@ -88,7 +88,7 @@ def items_for_tree_result(cl, result, form):
else:
attr = pk
value = result.serializable_value(attr)
result_id = repr(force_unicode(value))[1:]
result_id = repr(force_text(value))[1:]
first = False
if django.VERSION[1] < 4:
yield mark_safe('<%s%s>%s<a href="%s"%s>%s</a></%s>' % \
@ -103,12 +103,12 @@ def items_for_tree_result(cl, result, form):
# can provide fields on a per request basis
if form and field_name in form.fields:
bf = form[field_name]
result_repr = mark_safe(force_unicode(bf.errors) + force_unicode(bf))
result_repr = mark_safe(force_text(bf.errors) + force_text(bf))
else:
result_repr = conditional_escape(result_repr)
yield mark_safe('<td%s>%s</td>' % (row_class, result_repr))
if form and not form[cl.model._meta.pk.name].is_hidden:
yield mark_safe('<td>%s</td>' % force_unicode(form[cl.model._meta.pk.name]))
yield mark_safe('<td>%s</td>' % force_text(form[cl.model._meta.pk.name]))
class TreeList(list):

View file

@ -125,7 +125,7 @@ class TreeEditor(admin.ModelAdmin):
"The 'change list' admin view for this model."
from django.contrib.admin.views.main import ERROR_FLAG
from django.core.exceptions import PermissionDenied
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.translation import ungettext
opts = self.model._meta
app_label = opts.app_label
@ -199,15 +199,15 @@ class TreeEditor(admin.ModelAdmin):
if changecount:
if changecount == 1:
name = force_unicode(opts.verbose_name)
name = force_text(opts.verbose_name)
else:
name = force_unicode(opts.verbose_name_plural)
name = force_text(opts.verbose_name_plural)
msg = ungettext(
"%(count)s %(name)s was changed successfully.",
"%(count)s %(name)s were changed successfully.",
changecount) % {'count': changecount,
'name': name,
'obj': force_unicode(obj)}
'obj': force_text(obj)}
self.message_user(request, msg)
return HttpResponseRedirect(request.get_full_path())
@ -248,7 +248,7 @@ class TreeEditor(admin.ModelAdmin):
'All %(total_count)s selected', cl.result_count)
context.update({
'module_name': force_unicode(opts.verbose_name_plural),
'module_name': force_text(opts.verbose_name_plural),
'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
'selection_note_all': selection_note_all % {'total_count': cl.result_count},
})

View file

@ -1,7 +1,7 @@
"""
Provides compatibility with Django 1.1
Copied from django.contrib.admin.util
Copied from django.contrib.admin.utils
"""
from django.forms.forms import pretty_name
from django.db import models