Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7982 -- Corrected ModelAdmin url dispatching to ensure it matc…

…hing exactly what it needs and doesn't stomp on primary key space. 'add' is a lost cause for now. This originated from #6470. Thanks jdetaeye for the original patch and basith for providing test cases.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8704 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cd0b65bcf79dc61481d94a415a1598bb510d21c9 1 parent ddf7d7a
Brian Rosner authored August 29, 2008
6  django/contrib/admin/options.py
@@ -186,11 +186,11 @@ def __call__(self, request, url):
186 186
         # Delegate to the appropriate method, based on the URL.
187 187
         if url is None:
188 188
             return self.changelist_view(request)
189  
-        elif url.endswith('add'):
  189
+        elif url == "add":
190 190
             return self.add_view(request)
191  
-        elif url.endswith('history'):
  191
+        elif url.endswith('/history'):
192 192
             return self.history_view(request, unquote(url[:-8]))
193  
-        elif url.endswith('delete'):
  193
+        elif url.endswith('/delete'):
194 194
             return self.delete_view(request, unquote(url[:-7]))
195 195
         else:
196 196
             return self.change_view(request, unquote(url))
25  tests/regressiontests/admin_views/tests.py
@@ -458,6 +458,31 @@ def test_deleteconfirmation_link(self):
458 458
         response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk))
459 459
         should_contain = """<a href="../../%s/">%s</a>""" % (quote(self.pk), escape(self.pk))
460 460
         self.assertContains(response, should_contain)
  461
+    
  462
+    def test_url_conflicts_with_add(self):
  463
+        "A model with a primary key that ends with add should be visible"
  464
+        add_model = ModelWithStringPrimaryKey(id="i have something to add")
  465
+        add_model.save()
  466
+        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk))
  467
+        should_contain = """<h1>Change model with string primary key</h1>"""
  468
+        self.assertContains(response, should_contain)
  469
+    
  470
+    def test_url_conflicts_with_delete(self):
  471
+        "A model with a primary key that ends with delete should be visible"
  472
+        delete_model = ModelWithStringPrimaryKey(id="delete")
  473
+        delete_model.save()
  474
+        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk))
  475
+        should_contain = """<h1>Change model with string primary key</h1>"""
  476
+        self.assertContains(response, should_contain)
  477
+    
  478
+    def test_url_conflicts_with_history(self):
  479
+        "A model with a primary key that ends with history should be visible"
  480
+        history_model = ModelWithStringPrimaryKey(id="history")
  481
+        history_model.save()
  482
+        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk))
  483
+        should_contain = """<h1>Change model with string primary key</h1>"""
  484
+        self.assertContains(response, should_contain)
  485
+        
461 486
 
462 487
 class SecureViewTest(TestCase):
463 488
     fixtures = ['admin-views-users.xml']

0 notes on commit cd0b65b

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