mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Fixed a unicode error that happens with Python 2.7
This commit is contained in:
parent
d71d057a18
commit
fb0174c0a8
2 changed files with 25 additions and 26 deletions
|
|
@ -96,27 +96,18 @@ def items_for_tree_result(cl, result, form):
|
|||
value = result.serializable_value(attr)
|
||||
result_id = repr(force_text(value))[1:]
|
||||
first = False
|
||||
if django.VERSION[1] < 4: # versions 1.3 and smaller
|
||||
yield mark_safe(
|
||||
'<%s%s>%s<a href="%s"%s>%s</a></%s>' %
|
||||
(table_tag, row_class, checkbox_value, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
|
||||
elif django.VERSION[1] < 7: # versions 1.4 to 1.7
|
||||
yield mark_safe(
|
||||
'<%s%s><a href="%s"%s>%s</a></%s>' %
|
||||
(table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
|
||||
else: # versions 1.8 and greater
|
||||
result_id = escapejs(value)
|
||||
yield mark_safe(
|
||||
result_id = escapejs(value)
|
||||
yield mark_safe(
|
||||
format_html(
|
||||
smart_text('<{}{}><a href="{}"{}>{}</a></{}>'),
|
||||
table_tag,
|
||||
row_class,
|
||||
url,
|
||||
format_html(
|
||||
'<{}{}><a href="{}"{}>{}</a></{}>',
|
||||
table_tag,
|
||||
row_class,
|
||||
url,
|
||||
format_html(
|
||||
' onclick="opener.dismissRelatedLookupPopup(window, '
|
||||
''{}'); return false;"', result_id
|
||||
) if cl.is_popup else '', result_repr, table_tag)
|
||||
)
|
||||
' onclick="opener.dismissRelatedLookupPopup(window, '
|
||||
''{}'); return false;"', result_id
|
||||
) if cl.is_popup else '', result_repr, table_tag)
|
||||
)
|
||||
|
||||
else:
|
||||
# By default the fields come from ModelAdmin.list_editable, but if we pull
|
||||
|
|
@ -127,9 +118,9 @@ def items_for_tree_result(cl, result, form):
|
|||
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))
|
||||
yield mark_safe(smart_text('<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_text(form[cl.model._meta.pk.name]))
|
||||
yield mark_safe(smart_text('<td>%s</td>' % force_text(form[cl.model._meta.pk.name])))
|
||||
|
||||
|
||||
class TreeList(list):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import Client, TestCase
|
||||
from django.utils.encoding import smart_text
|
||||
|
||||
from categories.models import Category
|
||||
|
||||
|
|
@ -16,7 +19,7 @@ class TestCategoryAdmin(TestCase):
|
|||
url = reverse('admin:categories_category_add')
|
||||
data = {
|
||||
'parent': '',
|
||||
'name': "Parent",
|
||||
'name': smart_text('Parent Catégory'),
|
||||
'thumbnail': '',
|
||||
'filename': '',
|
||||
'active': 'on',
|
||||
|
|
@ -34,7 +37,7 @@ class TestCategoryAdmin(TestCase):
|
|||
self.assertEqual(1, Category.objects.count())
|
||||
|
||||
# update parent
|
||||
data.update({'name': 'Parent (Changed)'})
|
||||
data.update({'name': smart_text('Parent Catégory (Changed)')})
|
||||
resp = self.client.post(reverse('admin:categories_category_change', args=(1,)), data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(1, Category.objects.count())
|
||||
|
|
@ -42,8 +45,8 @@ class TestCategoryAdmin(TestCase):
|
|||
# add a child
|
||||
data.update({
|
||||
'parent': '1',
|
||||
'name': 'Child',
|
||||
'slug': 'child',
|
||||
'name': smart_text('Child Catégory'),
|
||||
'slug': smart_text('child-category'),
|
||||
})
|
||||
resp = self.client.post(url, data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
|
|
@ -54,3 +57,8 @@ class TestCategoryAdmin(TestCase):
|
|||
resp = self.client.post(reverse('admin:categories_category_change', args=(2,)), data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(2, Category.objects.count())
|
||||
|
||||
# test the admin list view
|
||||
url = reverse('admin:categories_category_changelist')
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
|
|
|||
Loading…
Reference in a new issue