Ticket #7923: ticket7923-3.patch

File ticket7923-3.patch, 4.5 KB (added by mrts, 15 years ago)

Fix a copy-paste from test output that hardcoded admin media prefix.

  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index fb5acb5..3a7a6f2 100644
    a b class ForeignKeyRawIdWidget(forms.TextInput):  
    149149    def label_for_value(self, value):
    150150        key = self.rel.get_related_field().name
    151151        obj = self.rel.to._default_manager.get(**{key: value})
    152         return '&nbsp;<strong>%s</strong>' % escape(truncate_words(obj, 14))
     152        related_url = '../../../%s/%s/%s/' % (obj._meta.app_label,
     153                obj._meta.object_name.lower(), obj.pk)
     154        return '&nbsp;<strong><a href="%s">%s</a></strong>' % (related_url,
     155                escape(truncate_words(obj, 14)))
    153156
    154157class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
    155158    """
  • tests/regressiontests/admin_widgets/models.py

    diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
    index 0c81ed3..564bcc5 100644
    a b from django.db import models  
    44from django.core.files.storage import default_storage
    55from django.contrib.auth.models import User
    66
    7 class MyFileField(models.FileField): 
    8     pass 
     7class MyFileField(models.FileField):
     8    pass
    99
    1010class Member(models.Model):
    1111    name = models.CharField(max_length=100)
    Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">alb  
    107107>>> rel = Album._meta.get_field('band').rel
    108108>>> w = ForeignKeyRawIdWidget(rel)
    109109>>> print conditional_escape(w.render('test', band.pk, attrs={}))
    110 <input type="text" name="test" value="1" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>
     110<input type="text" name="test" value="1" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong><a href="../../../admin_widgets/band/1/">Linkin Park</a></strong>
    111111
    112112>>> m1 = Member.objects.create(pk=1, name='Chester')
    113113>>> m2 = Member.objects.create(pk=2, name='Mike')
    True  
    138138>>> rel = Inventory._meta.get_field('parent').rel
    139139>>> w = ForeignKeyRawIdWidget(rel)
    140140>>> print w.render('test', core.parent_id, attrs={})
    141 <input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>
     141<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong><a href="../../../admin_widgets/inventory/1/">Apple</a></strong>
    142142
    143143# see #9258
    144144>>> hidden = Inventory.objects.create(barcode=93, name='Hidden', hidden=True)
    145145>>> child_of_hidden = Inventory.objects.create(barcode=94, name='Child of hidden', parent=hidden)
    146146>>> print w.render('test', child_of_hidden.parent_id, attrs={})
    147 <input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>
     147<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong><a href="../../../admin_widgets/inventory/4/">Hidden</a></strong>
    148148""" % {
    149149    'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
    150150    'STORAGE_URL': default_storage.url(''),
Back to Top