Ticket #9859: admin_unicode_fixes.diff

File admin_unicode_fixes.diff, 7.2 KB (added by Nils Fredrik Gjerull, 16 years ago)
  • django/contrib/admin/util.py

     
    104104                if not has_admin:
    105105                    # Don't display link to edit, because it either has no
    106106                    # 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)), []])
    108108                else:
    109109                    # Display a link to the admin page.
    110110                    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">&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>
  • tests/regressiontests/admin_views/tests.py

     
    684684        self.client.post('/test_admin/admin/secure-view/', self.super_login)
    685685        # make sure the view removes test cookie
    686686        self.failUnlessEqual(self.client.session.test_cookie_worked(), False)
     687
     688class 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/')
  • tests/regressiontests/admin_views/models.py

     
    2424        return self.date.year
    2525    model_year.admin_order_field = 'date'
    2626
     27class Book(models.Model):
     28    """
     29    A simple book that has chapters.
     30    """
     31    name = models.CharField(max_length=100)
     32
     33class 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
    2741def callable_year(dt_value):
    2842    return dt_value.year
    2943callable_year.admin_order_field = 'date'
     
    3145class ArticleInline(admin.TabularInline):
    3246    model = Article
    3347
     48class ChapterInline(admin.TabularInline):
     49    model = Chapter
     50
    3451class ArticleAdmin(admin.ModelAdmin):
    3552    list_display = ('content', 'date', callable_year, 'model_year', 'modeladmin_year')
    3653    list_filter = ('date',)
     
    92109admin.site.register(Article, ArticleAdmin)
    93110admin.site.register(CustomArticle, CustomArticleAdmin)
    94111admin.site.register(Section, inlines=[ArticleInline])
     112admin.site.register(Book, inlines=[ChapterInline])
    95113admin.site.register(ModelWithStringPrimaryKey)
    96114admin.site.register(Color)
    97115admin.site.register(Thing, ThingAdmin)
Back to Top