Follow-up to r9656 -- beef up the added test to exercise all (one can hope) paths through the troublesome get_deleted_objects function and fix the resulting errors.
Refs #9859. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9657 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
10894da8a8
commit
986e162c5d
|
@ -88,14 +88,16 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
|
||||||
if not has_admin:
|
if not has_admin:
|
||||||
# Don't display link to edit, because it either has no
|
# Don't display link to edit, because it either has no
|
||||||
# admin or is edited inline.
|
# admin or is edited inline.
|
||||||
nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []])
|
nh(deleted_objects, current_depth,
|
||||||
|
[u'%s: %s' % (capfirst(related.opts.verbose_name), force_unicode(sub_obj)), []])
|
||||||
else:
|
else:
|
||||||
# Display a link to the admin page.
|
# Display a link to the admin page.
|
||||||
nh(deleted_objects, current_depth, [mark_safe(u'%s: <a href="../../../../%s/%s/%s/">%s</a>' %
|
nh(deleted_objects, current_depth, [mark_safe(u'%s: <a href="../../../../%s/%s/%s/">%s</a>' %
|
||||||
(escape(force_unicode(capfirst(related.opts.verbose_name))),
|
(escape(capfirst(related.opts.verbose_name)),
|
||||||
related.opts.app_label,
|
related.opts.app_label,
|
||||||
related.opts.object_name.lower(),
|
related.opts.object_name.lower(),
|
||||||
sub_obj._get_pk_val(), sub_obj)), []])
|
sub_obj._get_pk_val(),
|
||||||
|
escape(sub_obj))), []])
|
||||||
get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
|
get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
|
||||||
else:
|
else:
|
||||||
has_related_objs = False
|
has_related_objs = False
|
||||||
|
@ -104,11 +106,16 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
|
||||||
if not has_admin:
|
if not has_admin:
|
||||||
# Don't display link to edit, because it either has no
|
# Don't display link to edit, because it either has no
|
||||||
# admin or is edited inline.
|
# admin or is edited inline.
|
||||||
nh(deleted_objects, current_depth, [u'%s: %s' % (capfirst(related.opts.verbose_name), force_unicode(sub_obj)), []])
|
nh(deleted_objects, current_depth,
|
||||||
|
[u'%s: %s' % (capfirst(related.opts.verbose_name), force_unicode(sub_obj)), []])
|
||||||
else:
|
else:
|
||||||
# Display a link to the admin page.
|
# Display a link to the admin page.
|
||||||
nh(deleted_objects, current_depth, [mark_safe(u'%s: <a href="../../../../%s/%s/%s/">%s</a>' % \
|
nh(deleted_objects, current_depth, [mark_safe(u'%s: <a href="../../../../%s/%s/%s/">%s</a>' %
|
||||||
(escape(force_unicode(capfirst(related.opts.verbose_name))), related.opts.app_label, related.opts.object_name.lower(), sub_obj._get_pk_val(), escape(sub_obj))), []])
|
(escape(capfirst(related.opts.verbose_name)),
|
||||||
|
related.opts.app_label,
|
||||||
|
related.opts.object_name.lower(),
|
||||||
|
sub_obj._get_pk_val(),
|
||||||
|
escape(sub_obj))), []])
|
||||||
get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
|
get_deleted_objects(deleted_objects, perms_needed, user, sub_obj, related.opts, current_depth+2, admin_site)
|
||||||
# If there were related objects, and the user doesn't have
|
# If there were related objects, and the user doesn't have
|
||||||
# permission to delete them, add the missing perm to perms_needed.
|
# permission to delete them, add the missing perm to perms_needed.
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
<object pk="1" model="admin_views.book">
|
<object pk="1" model="admin_views.book">
|
||||||
<field type="CharField" name="name">Lærdommer</field>
|
<field type="CharField" name="name">Lærdommer</field>
|
||||||
</object>
|
</object>
|
||||||
|
<object pk="1" model="admin_views.promo">
|
||||||
|
<field type="CharField" name="name"><Promo for Lærdommer></field>
|
||||||
|
<field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
|
||||||
|
</object>
|
||||||
<object pk="1" model="admin_views.chapter">
|
<object pk="1" model="admin_views.chapter">
|
||||||
<field type="CharField" name="title">Norske bostaver æøå skaper problemer</field>
|
<field type="CharField" name="title">Norske bostaver æøå skaper problemer</field>
|
||||||
<field type="TextField" name="content"><p>Svært frustrerende med UnicodeDecodeErro</p></field>
|
<field type="TextField" name="content"><p>Svært frustrerende med UnicodeDecodeErro</p></field>
|
||||||
|
@ -32,4 +36,28 @@
|
||||||
<field type="TextField" name="content"><p>Noe innhold</p></field>
|
<field type="TextField" name="content"><p>Noe innhold</p></field>
|
||||||
<field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
|
<field to="admin_views.book" name="book" rel="ManyToOneRel">1</field>
|
||||||
</object>
|
</object>
|
||||||
|
<object pk="1" model="admin_views.chapterxtra1">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(1) Norske bostaver æøå skaper problemer></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">1</field>
|
||||||
|
</object>
|
||||||
|
<object pk="2" model="admin_views.chapterxtra1">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(1) Kjærlighet></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">2</field>
|
||||||
|
</object>
|
||||||
|
<object pk="3" model="admin_views.chapterxtra1">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(1) Kjærlighet></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">3</field>
|
||||||
|
</object>
|
||||||
|
<object pk="1" model="admin_views.chapterxtra2">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(2) Norske bostaver æøå skaper problemer></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">1</field>
|
||||||
|
</object>
|
||||||
|
<object pk="2" model="admin_views.chapterxtra2">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(2) Kjærlighet></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">2</field>
|
||||||
|
</object>
|
||||||
|
<object pk="3" model="admin_views.chapterxtra2">
|
||||||
|
<field type="CharField" name="xtra"><Xtra(2) Kjærlighet></field>
|
||||||
|
<field to="admin_views.chapter" name="chap" rel="OneToOneRel">3</field>
|
||||||
|
</object>
|
||||||
</django-objects>
|
</django-objects>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
@ -28,16 +29,43 @@ class Book(models.Model):
|
||||||
"""
|
"""
|
||||||
A simple book that has chapters.
|
A simple book that has chapters.
|
||||||
"""
|
"""
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100, verbose_name=u'¿Name?')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Promo(models.Model):
|
||||||
|
name = models.CharField(max_length=100, verbose_name=u'¿Name?')
|
||||||
|
book = models.ForeignKey(Book)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class Chapter(models.Model):
|
class Chapter(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100, verbose_name=u'¿Title?')
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
book = models.ForeignKey(Book)
|
book = models.ForeignKey(Book)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = u'¿Chapter?'
|
||||||
|
|
||||||
|
class ChapterXtra1(models.Model):
|
||||||
|
chap = models.OneToOneField(Chapter, verbose_name=u'¿Chap?')
|
||||||
|
xtra = models.CharField(max_length=100, verbose_name=u'¿Xtra?')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u'¿Xtra1: %s' % self.xtra
|
||||||
|
|
||||||
|
class ChapterXtra2(models.Model):
|
||||||
|
chap = models.OneToOneField(Chapter, verbose_name=u'¿Chap?')
|
||||||
|
xtra = models.CharField(max_length=100, verbose_name=u'¿Xtra?')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u'¿Xtra2: %s' % self.xtra
|
||||||
|
|
||||||
def callable_year(dt_value):
|
def callable_year(dt_value):
|
||||||
return dt_value.year
|
return dt_value.year
|
||||||
callable_year.admin_order_field = 'date'
|
callable_year.admin_order_field = 'date'
|
||||||
|
@ -109,7 +137,19 @@ class ThingAdmin(admin.ModelAdmin):
|
||||||
admin.site.register(Article, ArticleAdmin)
|
admin.site.register(Article, ArticleAdmin)
|
||||||
admin.site.register(CustomArticle, CustomArticleAdmin)
|
admin.site.register(CustomArticle, CustomArticleAdmin)
|
||||||
admin.site.register(Section, inlines=[ArticleInline])
|
admin.site.register(Section, inlines=[ArticleInline])
|
||||||
admin.site.register(Book, inlines=[ChapterInline])
|
|
||||||
admin.site.register(ModelWithStringPrimaryKey)
|
admin.site.register(ModelWithStringPrimaryKey)
|
||||||
admin.site.register(Color)
|
admin.site.register(Color)
|
||||||
admin.site.register(Thing, ThingAdmin)
|
admin.site.register(Thing, ThingAdmin)
|
||||||
|
|
||||||
|
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
|
||||||
|
# That way we cover all four cases:
|
||||||
|
# related ForeignKey object registered in admin
|
||||||
|
# related ForeignKey object not registered in admin
|
||||||
|
# related OneToOne object registered in admin
|
||||||
|
# related OneToOne object not registered in admin
|
||||||
|
# when deleting Book so as exercise all four troublesome (w.r.t escaping
|
||||||
|
# and calling force_unicode to avoid problems on Python 2.3) paths through
|
||||||
|
# contrib.admin.util's get_deleted_objects function.
|
||||||
|
admin.site.register(Book, inlines=[ChapterInline])
|
||||||
|
admin.site.register(Promo)
|
||||||
|
admin.site.register(ChapterXtra1)
|
||||||
|
|
Loading…
Reference in New Issue