Ticket #17200: 17200-patch-and-test.diff

File 17200-patch-and-test.diff, 2.6 KB (added by dchandek, 3 years ago)

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

  • django/contrib/admin/options.py

     
    10881088        context = {
    10891089            'title': _('Change %s') % force_unicode(opts.verbose_name),
    10901090            'adminform': adminForm,
    1091             'object_id': object_id,
     1091            'object_id': unquote(object_id),
    10921092            'original': obj,
    10931093            'is_popup': "_popup" in request.REQUEST,
    10941094            'media': mark_safe(media),
  • tests/regressiontests/admin_views/tests.py

     
    1414from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
    1515from django.contrib.admin.models import LogEntry, DELETION
    1616from django.contrib.admin.sites import LOGIN_FORM_KEY
    17 from django.contrib.admin.util import quote
     17from django.contrib.admin.util import quote, unquote
    1818from django.contrib.admin.views.main import IS_POPUP_VAR
    1919from django.contrib.auth import REDIRECT_FIELD_NAME, admin
    2020from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
     
    12061206        response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(self.pk))
    12071207        self.assertContains(response, escape(self.pk))
    12081208        self.assertEqual(response.status_code, 200)
     1209        content_type_pk = ContentType.objects.get_for_model(ModelWithStringPrimaryKey).pk
     1210        should_contain = """<a href="../../../r/%s/%s/" class="viewsitelink">View on site</a>""" % (content_type_pk, escape(self.pk))
     1211        self.assertContains(response, should_contain)
    12091212
    12101213    def test_changelist_to_changeform_link(self):
    12111214        "The link from the changelist referring to the changeform of the object should be quoted"
  • tests/regressiontests/admin_views/models.py

     
    9999    def __unicode__(self):
    100100        return self.id
    101101
     102    def get_absolute_url(self):
     103        # Need this to cause "view on site" link to appear on admin change form.
     104        # We're not testing the specific URL produced by this method.
     105        return '/%s/' % self.id
    102106
     107
    103108class Color(models.Model):
    104109    value = models.CharField(max_length=10)
    105110    warm = models.BooleanField()
Back to Top