Author: brosner
Date: 2008-08-29 11:46:46 -0500 (Fri, 29 Aug 2008)
New Revision: 8704

Modified:
   django/trunk/django/contrib/admin/options.py
   django/trunk/tests/regressiontests/admin_views/tests.py
Log:
Fixed #7982 -- Corrected ModelAdmin url dispatching to ensure it matching 
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.

Modified: django/trunk/django/contrib/admin/options.py
===================================================================
--- django/trunk/django/contrib/admin/options.py        2008-08-29 16:32:44 UTC 
(rev 8703)
+++ django/trunk/django/contrib/admin/options.py        2008-08-29 16:46:46 UTC 
(rev 8704)
@@ -186,11 +186,11 @@
         # Delegate to the appropriate method, based on the URL.
         if url is None:
             return self.changelist_view(request)
-        elif url.endswith('add'):
+        elif url == "add":
             return self.add_view(request)
-        elif url.endswith('history'):
+        elif url.endswith('/history'):
             return self.history_view(request, unquote(url[:-8]))
-        elif url.endswith('delete'):
+        elif url.endswith('/delete'):
             return self.delete_view(request, unquote(url[:-7]))
         else:
             return self.change_view(request, unquote(url))

Modified: django/trunk/tests/regressiontests/admin_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/tests.py     2008-08-29 
16:32:44 UTC (rev 8703)
+++ django/trunk/tests/regressiontests/admin_views/tests.py     2008-08-29 
16:46:46 UTC (rev 8704)
@@ -458,6 +458,31 @@
         response = 
self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/'
 % quote(self.pk))
         should_contain = """<a href="../../%s/">%s</a>""" % (quote(self.pk), 
escape(self.pk))
         self.assertContains(response, should_contain)
+    
+    def test_url_conflicts_with_add(self):
+        "A model with a primary key that ends with add should be visible"
+        add_model = ModelWithStringPrimaryKey(id="i have something to add")
+        add_model.save()
+        response = 
self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % 
quote(add_model.pk))
+        should_contain = """<h1>Change model with string primary key</h1>"""
+        self.assertContains(response, should_contain)
+    
+    def test_url_conflicts_with_delete(self):
+        "A model with a primary key that ends with delete should be visible"
+        delete_model = ModelWithStringPrimaryKey(id="delete")
+        delete_model.save()
+        response = 
self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % 
quote(delete_model.pk))
+        should_contain = """<h1>Change model with string primary key</h1>"""
+        self.assertContains(response, should_contain)
+    
+    def test_url_conflicts_with_history(self):
+        "A model with a primary key that ends with history should be visible"
+        history_model = ModelWithStringPrimaryKey(id="history")
+        history_model.save()
+        response = 
self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % 
quote(history_model.pk))
+        should_contain = """<h1>Change model with string primary key</h1>"""
+        self.assertContains(response, should_contain)
+        
 
 class SecureViewTest(TestCase):
     fixtures = ['admin-views-users.xml']


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to