Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
authored June 18, 2008
1  AUTHORS
@@ -315,6 +315,7 @@ answer newbie questions, and generally made Django that much better:
315 315
     Matt Riggott
316 316
     Henrique Romano <onaiort@gmail.com>
317 317
     Armin Ronacher
  318
+    Daniel Roseman <http://roseman.org.uk/>    
318 319
     Brian Rosner <brosner@gmail.com>
319 320
     Oliver Rutherfurd <http://rutherfurd.net/>
320 321
     ryankanno
4  django/contrib/admin/util.py
@@ -19,7 +19,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
19 19
         return # Avoid recursing too deep.
20 20
     opts_seen = []
21 21
     for related in opts.get_all_related_objects():
22  
-        has_admin = related.__class__ in admin_site._registry
  22
+        has_admin = related.model in admin_site._registry
23 23
         if related.opts in opts_seen:
24 24
             continue
25 25
         opts_seen.append(related.opts)
@@ -68,7 +68,7 @@ def get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current_
68 68
                 if not user.has_perm(p):
69 69
                     perms_needed.add(related.opts.verbose_name)
70 70
     for related in opts.get_all_related_many_to_many_objects():
71  
-        has_admin = related.__class__ in admin_site._registry
  71
+        has_admin = related.model in admin_site._registry
72 72
         if related.opts in opts_seen:
73 73
             continue
74 74
         opts_seen.append(related.opts)
4  tests/regressiontests/admin_views/fixtures/admin-views-users.xml
@@ -70,8 +70,12 @@
70 70
         <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
71 71
         <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
72 72
     </object>
  73
+    <object pk="1" model="admin_views.section">
  74
+        <field type="CharField" name="name">Test section</field>
  75
+    </object>
73 76
     <object pk="1" model="admin_views.article">
74 77
         <field type="TextField" name="content">&lt;p&gt;test content&lt;/p&gt;</field>
75 78
         <field type="DateTimeField" name="date">2008-03-18 11:54:58</field>
  79
+        <field to="admin_views.section" name="section" rel="ManyToOneRel">1</field>
76 80
     </object>
77 81
 </django-objects>
27  tests/regressiontests/admin_views/models.py
... ...
@@ -1,12 +1,20 @@
1 1
 from django.db import models
2 2
 from django.contrib import admin
3 3
 
  4
+class Section(models.Model):
  5
+    """
  6
+    A simple section that links to articles, to test linking to related items 
  7
+    in admin views.
  8
+    """
  9
+    name = models.CharField(max_length=100)
  10
+
4 11
 class Article(models.Model):
5 12
     """
6  
-    A simple article to test admin views. Test backwards compabilty.
  13
+    A simple article to test admin views. Test backwards compatibility.
7 14
     """
8 15
     content = models.TextField()
9 16
     date = models.DateTimeField()
  17
+    section = models.ForeignKey(Section)
10 18
 
11 19
 class ArticleAdmin(admin.ModelAdmin):
12 20
     list_display = ('content', 'date')
@@ -14,9 +22,11 @@ class ArticleAdmin(admin.ModelAdmin):
14 22
     
15 23
     def changelist_view(self, request):
16 24
         "Test that extra_context works"
17  
-        return super(ArticleAdmin, self).changelist_view(request, extra_context={
18  
-            'extra_var': 'Hello!'
19  
-        })
  25
+        return super(ArticleAdmin, self).changelist_view(
  26
+            request, extra_context={
  27
+                'extra_var': 'Hello!'
  28
+            }
  29
+        )
20 30
 
21 31
 class CustomArticle(models.Model):
22 32
     content = models.TextField()
@@ -33,9 +43,12 @@ class CustomArticleAdmin(admin.ModelAdmin):
33 43
     
34 44
     def changelist_view(self, request):
35 45
         "Test that extra_context works"
36  
-        return super(CustomArticleAdmin, self).changelist_view(request, extra_context={
37  
-            'extra_var': 'Hello!'
38  
-        })
  46
+        return super(CustomArticleAdmin, self).changelist_view(
  47
+            request, extra_context={
  48
+                'extra_var': 'Hello!'
  49
+            }
  50
+        )
39 51
         
40 52
 admin.site.register(Article, ArticleAdmin)
41 53
 admin.site.register(CustomArticle, CustomArticleAdmin)
  54
+admin.site.register(Section)
19  tests/regressiontests/admin_views/tests.py
@@ -5,7 +5,7 @@
5 5
 from django.contrib.admin.sites import LOGIN_FORM_KEY, _encode_post_data
6 6
 
7 7
 # local test models
8  
-from models import Article, CustomArticle
  8
+from models import Article, CustomArticle, Section
9 9
 
10 10
 def get_perm(Model, perm):
11 11
     """Return the permission object, for the Model"""
@@ -40,6 +40,9 @@ def setUp(self):
40 40
         delete_user = User.objects.get(username='deleteuser')
41 41
         delete_user.user_permissions.add(get_perm(Article,
42 42
             opts.get_delete_permission()))
  43
+
  44
+        delete_user.user_permissions.add(get_perm(Section,
  45
+            Section._meta.get_delete_permission()))
43 46
         
44 47
         # login POST dicts
45 48
         self.super_login = {'post_data': _encode_post_data({}),
@@ -116,7 +119,8 @@ def testAddView(self):
116 119
         """Test add view restricts access and actually adds items."""
117 120
         
118 121
         add_dict = {'content': '<p>great article</p>',
119  
-                    'date_0': '2008-03-18', 'date_1': '10:54:39'}
  122
+                    'date_0': '2008-03-18', 'date_1': '10:54:39',
  123
+                    'section': 1}
120 124
         
121 125
         # Change User should not have access to add articles
122 126
         self.client.get('/test_admin/admin/')
@@ -158,7 +162,8 @@ def testChangeView(self):
158 162
         """Change view should restrict access and allow users to edit items."""
159 163
         
160 164
         change_dict = {'content': '<p>edited article</p>',
161  
-                    'date_0': '2008-03-18', 'date_1': '10:54:39'}
  165
+                    'date_0': '2008-03-18', 'date_1': '10:54:39',
  166
+                    'section': 1}
162 167
         
163 168
         # add user shoud not be able to view the list of article or change any of them
164 169
         self.client.get('/test_admin/admin/')
@@ -270,8 +275,12 @@ def testDeleteView(self):
270 275
         # Delete user can delete
271 276
         self.client.get('/test_admin/admin/')
272 277
         self.client.post('/test_admin/admin/', self.deleteuser_login)
273  
-        request = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
274  
-        self.failUnlessEqual(request.status_code, 200)
  278
+        response = self.client.get('/test_admin/admin/admin_views/section/1/delete/')
  279
+         # test response contains link to related Article
  280
+        self.assertContains(response, "admin_views/article/1/")
  281
+
  282
+        response = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
  283
+        self.failUnlessEqual(response.status_code, 200)
275 284
         post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict)
276 285
         # TODO: http://code.djangoproject.com/ticket/6819 or the next line fails
277 286
         self.assertRedirects(post, '/test_admin/admin/')

0 notes on commit 86a946a

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