Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9859 -- Added another missing force_unicode needed in admin wh…

…en running on Python 2.3. Many thanks for report & patch to nfg.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9656 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 10894da8a840a6d7d99add4bf372215b8a600f06 1 parent 5f78eff
Karen Tracey authored December 16, 2008
2  django/contrib/admin/util.py
@@ -104,7 +104,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
104 104
                 if not has_admin:
105 105
                     # Don't display link to edit, because it either has no
106 106
                     # admin or is edited inline.
107  
-                    nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []])
  107
+                    nh(deleted_objects, current_depth, [u'%s: %s' % (capfirst(related.opts.verbose_name), force_unicode(sub_obj)), []])
108 108
                 else:
109 109
                     # Display a link to the admin page.
110 110
                     nh(deleted_objects, current_depth, [mark_safe(u'%s: <a href="../../../../%s/%s/%s/">%s</a>' % \
35  tests/regressiontests/admin_views/fixtures/admin-views-unicode.xml
... ...
@@ -0,0 +1,35 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<django-objects version="1.0">
  3
+    <object pk="100" model="auth.user">
  4
+        <field type="CharField" name="username">super</field>
  5
+        <field type="CharField" name="first_name">Super</field>
  6
+        <field type="CharField" name="last_name">User</field>
  7
+        <field type="CharField" name="email">super@example.com</field>
  8
+        <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
  9
+        <field type="BooleanField" name="is_staff">True</field>
  10
+        <field type="BooleanField" name="is_active">True</field>
  11
+        <field type="BooleanField" name="is_superuser">True</field>
  12
+        <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
  13
+        <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
  14
+        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
  15
+        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
  16
+    </object>
  17
+    <object pk="1" model="admin_views.book">
  18
+        <field type="CharField" name="name">Lærdommer</field>
  19
+    </object>
  20
+    <object pk="1" model="admin_views.chapter">
  21
+        <field type="CharField" name="title">Norske bostaver æøå skaper problemer</field>
  22
+        <field type="TextField" name="content">&lt;p&gt;Svært frustrerende med UnicodeDecodeErro&lt;/p&gt;</field>
  23
+        <field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
  24
+    </object>
  25
+    <object pk="2" model="admin_views.chapter">
  26
+        <field type="CharField" name="title">Kjærlighet</field>
  27
+        <field type="TextField" name="content">&lt;p&gt;La kjærligheten til de lidende seire.&lt;/p&gt;</field>
  28
+        <field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
  29
+    </object>
  30
+    <object pk="3" model="admin_views.chapter">
  31
+        <field type="CharField" name="title">Kjærlighet</field>
  32
+        <field type="TextField" name="content">&lt;p&gt;Noe innhold&lt;/p&gt;</field>
  33
+        <field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
  34
+    </object>
  35
+</django-objects>
18  tests/regressiontests/admin_views/models.py
@@ -24,6 +24,20 @@ def model_year(self):
24 24
         return self.date.year
25 25
     model_year.admin_order_field = 'date'
26 26
 
  27
+class Book(models.Model):
  28
+    """
  29
+    A simple book that has chapters.
  30
+    """
  31
+    name = models.CharField(max_length=100)
  32
+
  33
+class Chapter(models.Model):
  34
+    title = models.CharField(max_length=100)
  35
+    content = models.TextField()
  36
+    book = models.ForeignKey(Book)
  37
+
  38
+    def __unicode__(self):
  39
+        return self.title
  40
+
27 41
 def callable_year(dt_value):
28 42
     return dt_value.year
29 43
 callable_year.admin_order_field = 'date'
@@ -31,6 +45,9 @@ def callable_year(dt_value):
31 45
 class ArticleInline(admin.TabularInline):
32 46
     model = Article
33 47
 
  48
+class ChapterInline(admin.TabularInline):
  49
+    model = Chapter
  50
+
34 51
 class ArticleAdmin(admin.ModelAdmin):
35 52
     list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year')
36 53
     list_filter = ('date',)
@@ -92,6 +109,7 @@ class ThingAdmin(admin.ModelAdmin):
92 109
 admin.site.register(Article, ArticleAdmin)
93 110
 admin.site.register(CustomArticle, CustomArticleAdmin)
94 111
 admin.site.register(Section, inlines=[ArticleInline])
  112
+admin.site.register(Book, inlines=[ChapterInline])
95 113
 admin.site.register(ModelWithStringPrimaryKey)
96 114
 admin.site.register(Color)
97 115
 admin.site.register(Thing, ThingAdmin)
51  tests/regressiontests/admin_views/tests.py
@@ -684,3 +684,54 @@ def test_staff_member_required_decorator_works_as_per_admin_login(self):
684 684
         self.client.post('/test_admin/admin/secure-view/', self.super_login)
685 685
         # make sure the view removes test cookie
686 686
         self.failUnlessEqual(self.client.session.test_cookie_worked(), False)
  687
+
  688
+class AdminViewUnicodeTest(TestCase):
  689
+    fixtures = ['admin-views-unicode.xml']
  690
+
  691
+    def setUp(self):
  692
+        self.client.login(username='super', password='secret')
  693
+
  694
+    def tearDown(self):
  695
+        self.client.logout()
  696
+
  697
+    def testUnicodeEdit(self):
  698
+        """
  699
+        A test to ensure that POST on edit_view handles non-ascii characters.
  700
+        """
  701
+        post_data = {
  702
+            "name": u"Test lærdommer",
  703
+            # inline data
  704
+            "chapter_set-TOTAL_FORMS": u"6",
  705
+            "chapter_set-INITIAL_FORMS": u"3",
  706
+            "chapter_set-0-id": u"1",
  707
+            "chapter_set-0-title": u"Norske bostaver æøå skaper problemer",
  708
+            "chapter_set-0-content": u"&lt;p&gt;Svært frustrerende med UnicodeDecodeError&lt;/p&gt;",
  709
+            "chapter_set-1-id": u"2",
  710
+            "chapter_set-1-title": u"Kjærlighet.",
  711
+            "chapter_set-1-content": u"&lt;p&gt;La kjærligheten til de lidende seire.&lt;/p&gt;",
  712
+            "chapter_set-2-id": u"3",
  713
+            "chapter_set-2-title": u"Need a title.",
  714
+            "chapter_set-2-content": u"&lt;p&gt;Newest content&lt;/p&gt;",
  715
+            "chapter_set-3-id": u"",
  716
+            "chapter_set-3-title": u"",
  717
+            "chapter_set-3-content": u"",
  718
+            "chapter_set-4-id": u"",
  719
+            "chapter_set-4-title": u"",
  720
+            "chapter_set-4-content": u"",
  721
+            "chapter_set-5-id": u"",
  722
+            "chapter_set-5-title": u"",
  723
+            "chapter_set-5-content": u"",
  724
+        }
  725
+
  726
+        response = self.client.post('/test_admin/admin/admin_views/book/1/', post_data)
  727
+        self.failUnlessEqual(response.status_code, 302) # redirect somewhere
  728
+
  729
+    def testUnicodeDelete(self):
  730
+        """
  731
+        Ensure that the delete_view handles non-ascii characters
  732
+        """
  733
+        delete_dict = {'post': 'yes'}
  734
+        response = self.client.get('/test_admin/admin/admin_views/book/1/delete/')
  735
+        self.failUnlessEqual(response.status_code, 200)
  736
+        response = self.client.post('/test_admin/admin/admin_views/book/1/delete/', delete_dict)
  737
+        self.assertRedirects(response, '/test_admin/admin/admin_views/book/')

0 notes on commit 10894da

Please sign in to comment.
Something went wrong with that request. Please try again.