Ticket #9859: admin_unicode_fixes.diff
File admin_unicode_fixes.diff, 7.2 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/util.py
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>' % \ -
tests/regressiontests/admin_views/fixtures/admin-views-unicode.xml
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"><p>Svært frustrerende med UnicodeDecodeErro</p></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"><p>La kjærligheten til de lidende seire.</p></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"><p>Noe innhold</p></field> 33 <field to="admin_views.book" name="book" rel="ManyToOneRel">1</field> 34 </object> 35 </django-objects> -
tests/regressiontests/admin_views/tests.py
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"<p>Svært frustrerende med UnicodeDecodeError</p>", 709 "chapter_set-1-id": u"2", 710 "chapter_set-1-title": u"Kjærlighet.", 711 "chapter_set-1-content": u"<p>La kjærligheten til de lidende seire.</p>", 712 "chapter_set-2-id": u"3", 713 "chapter_set-2-title": u"Need a title.", 714 "chapter_set-2-content": u"<p>Newest content</p>", 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/') -
tests/regressiontests/admin_views/models.py
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 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 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)