Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20664 -- Fixed a bug with raw_id_fields on Python 3.

Thanks jefftriplett for the report.
  • Loading branch information...
commit 534ced5aadf964eca4cf29a689dc70185f582772 1 parent c1284c3
Tim Graham authored June 27, 2013
6  django/contrib/admin/templatetags/admin_list.py
@@ -11,7 +11,7 @@
11 11
 from django.core.exceptions import ObjectDoesNotExist
12 12
 from django.db import models
13 13
 from django.utils import formats
14  
-from django.utils.html import format_html
  14
+from django.utils.html import escapejs, format_html
15 15
 from django.utils.safestring import mark_safe
16 16
 from django.utils.text import capfirst
17 17
 from django.utils.translation import ugettext as _
@@ -226,12 +226,12 @@ def items_for_result(cl, result, form):
226 226
             else:
227 227
                 attr = pk
228 228
             value = result.serializable_value(attr)
229  
-            result_id = repr(force_text(value))[1:]
  229
+            result_id = escapejs(value)
230 230
             yield format_html('<{0}{1}><a href="{2}"{3}>{4}</a></{5}>',
231 231
                               table_tag,
232 232
                               row_class,
233 233
                               url,
234  
-                              format_html(' onclick="opener.dismissRelatedLookupPopup(window, {0}); return false;"', result_id)
  234
+                              format_html(' onclick="opener.dismissRelatedLookupPopup(window, &#39;{0}&#39;); return false;"', result_id)
235 235
                                 if cl.is_popup else '',
236 236
                               result_repr,
237 237
                               table_tag)
8  tests/admin_views/tests.py
@@ -583,6 +583,14 @@ def test_allowed_filtering_15103(self):
583 583
         response = self.client.get("/test_admin/admin/admin_views/inquisition/?leader__name=Palin&leader__age=27")
584 584
         self.assertEqual(response.status_code, 200)
585 585
 
  586
+    def test_popup_dismiss_related(self):
  587
+        """
  588
+        Regression test for ticket 20664 - ensure the pk is properly quoted.
  589
+        """
  590
+        actor = Actor.objects.create(name="Palin", age=27)
  591
+        response = self.client.get("/test_admin/admin/admin_views/actor/?%s" % IS_POPUP_VAR)
  592
+        self.assertContains(response, "opener.dismissRelatedLookupPopup(window, &#39;%s&#39;)" % actor.pk)
  593
+
586 594
     def test_hide_change_password(self):
587 595
         """
588 596
         Tests if the "change password" link in the admin is hidden if the User

0 notes on commit 534ced5

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