Opened 13 years ago

Closed 12 years ago

#17200 closed Bug (fixed)

"View on site" link breaks when quote(object_id) != object_id

Reported by: David Chandek-Stark Owned by: dlanger
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: David Chandek-Stark, ldelaveau@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The change_view method of django.contrib.admin.options.ModelAdmin returns object_id as passed in. This means that the "View on site" link breaks in cases where the django.contrib.admin.util.quote(object_id) != object_id.

There are two possible solutions:
1) Call django.contrib.admin.util.unquote() on object_id before returning to change_view template;
2) Call django.contrib.admin.util.unquote() on object_id in django.contrib.contenttypes.views.shortcut in this line: obj = content_type.get_object_for_this_type(pk=object_id).

Attached are svn diffs for each.

Attachments (3)

django.contrib.admin.options.diff (571 bytes ) - added by David Chandek-Stark 13 years ago.
django.contrib.contenttypes.views.diff (1.4 KB ) - added by David Chandek-Stark 13 years ago.
17200-patch-and-test.diff (2.6 KB ) - added by David Chandek-Stark 13 years ago.
Initial attempt at patch + unit test. Note that i18n not applied to "View on site" in test.

Download all attachments as: .zip

Change History (12)

by David Chandek-Stark, 13 years ago

by David Chandek-Stark, 13 years ago

comment:1 by David Chandek-Stark, 13 years ago

Cc: David Chandek-Stark added

comment:2 by Julien Phalip, 13 years ago

Component: Uncategorizedcontrib.admin
Needs tests: set
Triage Stage: UnreviewedAccepted

Solution 1) is the right one. Could you provide a test case? Thanks!

in reply to:  2 comment:3 by David Chandek-Stark, 13 years ago

Replying to julien:

Solution 1) is the right one. Could you provide a test case? Thanks!

Happy to take a crack at a test case. Since I've not contributed one to Django before, I'm not sure the more helpful way to do this. My first guess is to write a test_viewonsite_link method in the AdminViewStringPrimaryKeyTest class of tests/regressiontests/admin_views/tests.py.

by David Chandek-Stark, 13 years ago

Attachment: 17200-patch-and-test.diff added

Initial attempt at patch + unit test. Note that i18n not applied to "View on site" in test.

comment:4 by David Chandek-Stark, 13 years ago

I realized that the new test could just be added to the test_get_change_view() method. As noted, i18n may need to be applied to "View on site" text in test.

comment:5 by Claude Paroz, 12 years ago

Needs tests: unset

comment:6 by Claude Paroz, 12 years ago

I guess that this issue might have been fixed along #18444. Can someone confirm?

comment:7 by dlanger, 12 years ago

Owner: changed from nobody to dlanger
Status: newassigned

comment:8 by Ludovic Delaveau, 12 years ago

Cc: ldelaveau@… added

I have the feeling that the test test_shortcut_view_with_escaping at line 1453 in tests/regressiontests/admin_views/tests.py confirms that the issue is fixed:

def test_shortcut_view_with_escaping(self):                                                              
    "'View on site should' work properly with char fields"                                               
    model = ModelWithStringPrimaryKey(pk='abc_123')                                                      
    model.save()                                                                                         
    response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(model.pk))                                                                                                        
    should_contain = '/%s/" class="viewsitelink">' % model.pk                                            
    self.assertContains(response, should_contain)                                                        

comment:9 by Claude Paroz, 12 years ago

Resolution: fixed
Status: assignedclosed

OK, let's consider it fixed.

Note: See TracTickets for help on using tickets.
Back to Top