Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

newforms-admin: Fixed #7483 (thanks, Daniel Roseman) - delete view no…

…w correctly links to related objects

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7685 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 86a946a1a6be09e3d857f981313661565df3a449 1 parent de2f390
Simon Willison authored
View
1  AUTHORS
@@ -315,6 +315,7 @@ answer newbie questions, and generally made Django that much better:
Matt Riggott
Henrique Romano <onaiort@gmail.com>
Armin Ronacher
+ Daniel Roseman <http://roseman.org.uk/>
Brian Rosner <brosner@gmail.com>
Oliver Rutherfurd <http://rutherfurd.net/>
ryankanno
View
4 django/contrib/admin/util.py
@@ -19,7 +19,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
return # Avoid recursing too deep.
opts_seen = []
for related in opts.get_all_related_objects():
- has_admin = related.__class__ in admin_site._registry
+ has_admin = related.model in admin_site._registry
if related.opts in opts_seen:
continue
opts_seen.append(related.opts)
@@ -68,7 +68,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
if not user.has_perm(p):
perms_needed.add(related.opts.verbose_name)
for related in opts.get_all_related_many_to_many_objects():
- has_admin = related.__class__ in admin_site._registry
+ has_admin = related.model in admin_site._registry
if related.opts in opts_seen:
continue
opts_seen.append(related.opts)
View
4 tests/regressiontests/admin_views/fixtures/admin-views-users.xml
@@ -70,8 +70,12 @@
<field to="auth.group" name="groups" rel="ManyToManyRel"></field>
<field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
</object>
+ <object pk="1" model="admin_views.section">
+ <field type="CharField" name="name">Test section</field>
+ </object>
<object pk="1" model="admin_views.article">
<field type="TextField" name="content">&lt;p&gt;test content&lt;/p&gt;</field>
<field type="DateTimeField" name="date">2008-03-18 11:54:58</field>
+ <field to="admin_views.section" name="section" rel="ManyToOneRel">1</field>
</object>
</django-objects>
View
27 tests/regressiontests/admin_views/models.py
@@ -1,12 +1,20 @@
from django.db import models
from django.contrib import admin
+class Section(models.Model):
+ """
+ A simple section that links to articles, to test linking to related items
+ in admin views.
+ """
+ name = models.CharField(max_length=100)
+
class Article(models.Model):
"""
- A simple article to test admin views. Test backwards compabilty.
+ A simple article to test admin views. Test backwards compatibility.
"""
content = models.TextField()
date = models.DateTimeField()
+ section = models.ForeignKey(Section)
class ArticleAdmin(admin.ModelAdmin):
list_display = ('content', 'date')
@@ -14,9 +22,11 @@ class ArticleAdmin(admin.ModelAdmin):
def changelist_view(self, request):
"Test that extra_context works"
- return super(ArticleAdmin, self).changelist_view(request, extra_context={
- 'extra_var': 'Hello!'
- })
+ return super(ArticleAdmin, self).changelist_view(
+ request, extra_context={
+ 'extra_var': 'Hello!'
+ }
+ )
class CustomArticle(models.Model):
content = models.TextField()
@@ -33,9 +43,12 @@ class CustomArticleAdmin(admin.ModelAdmin):
def changelist_view(self, request):
"Test that extra_context works"
- return super(CustomArticleAdmin, self).changelist_view(request, extra_context={
- 'extra_var': 'Hello!'
- })
+ return super(CustomArticleAdmin, self).changelist_view(
+ request, extra_context={
+ 'extra_var': 'Hello!'
+ }
+ )
admin.site.register(Article, ArticleAdmin)
admin.site.register(CustomArticle, CustomArticleAdmin)
+admin.site.register(Section)
View
19 tests/regressiontests/admin_views/tests.py
@@ -5,7 +5,7 @@
from django.contrib.admin.sites import LOGIN_FORM_KEY, _encode_post_data
# local test models
-from models import Article, CustomArticle
+from models import Article, CustomArticle, Section
def get_perm(Model, perm):
"""Return the permission object, for the Model"""
@@ -40,6 +40,9 @@ def setUp(self):
delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Article,
opts.get_delete_permission()))
+
+ delete_user.user_permissions.add(get_perm(Section,
+ Section._meta.get_delete_permission()))
# login POST dicts
self.super_login = {'post_data': _encode_post_data({}),
@@ -116,7 +119,8 @@ def testAddView(self):
"""Test add view restricts access and actually adds items."""
add_dict = {'content': '<p>great article</p>',
- 'date_0': '2008-03-18', 'date_1': '10:54:39'}
+ 'date_0': '2008-03-18', 'date_1': '10:54:39',
+ 'section': 1}
# Change User should not have access to add articles
self.client.get('/test_admin/admin/')
@@ -158,7 +162,8 @@ def testChangeView(self):
"""Change view should restrict access and allow users to edit items."""
change_dict = {'content': '<p>edited article</p>',
- 'date_0': '2008-03-18', 'date_1': '10:54:39'}
+ 'date_0': '2008-03-18', 'date_1': '10:54:39',
+ 'section': 1}
# add user shoud not be able to view the list of article or change any of them
self.client.get('/test_admin/admin/')
@@ -270,8 +275,12 @@ def testDeleteView(self):
# Delete user can delete
self.client.get('/test_admin/admin/')
self.client.post('/test_admin/admin/', self.deleteuser_login)
- request = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
- self.failUnlessEqual(request.status_code, 200)
+ response = self.client.get('/test_admin/admin/admin_views/section/1/delete/')
+ # test response contains link to related Article
+ self.assertContains(response, "admin_views/article/1/")
+
+ response = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
+ self.failUnlessEqual(response.status_code, 200)
post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict)
# TODO: http://code.djangoproject.com/ticket/6819 or the next line fails
self.assertRedirects(post, '/test_admin/admin/')
Please sign in to comment.
Something went wrong with that request. Please try again.