Ticket #7028: improved-raw-id-admin-django-1.0.diff

File improved-raw-id-admin-django-1.0.diff, 3.7 KB (added by marcoberi@…, 7 years ago)
  • django/contrib/admin/media/js/admin/RelatedObjectLookups.js

     
    2626    return false;
    2727}
    2828
    29 function dismissRelatedLookupPopup(win, chosenId) {
     29function dismissRelatedLookupPopup(win, chosenId, chosenName) {
    3030    var name = win.name.replace(/___/g, '.');
    3131    var elem = document.getElementById(name);
     32    var nameElem = document.getElementById("view_lookup_" + name);
     33
    3234    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
    3335        elem.value += ',' + chosenId;
    3436    } else {
    3537        document.getElementById(name).value = chosenId;
    3638    }
     39    if(nameElem) {
     40      nameElem.innerHTML = chosenName;
     41    }
    3742    win.close();
    3843}
    3944
  • django/contrib/admin/templatetags/admin_list.py

     
    223223            else:
    224224                attr = pk
    225225            result_id = repr(force_unicode(getattr(result, attr)))[1:]
     226            result_name = repr(escape(force_unicode(result).replace("'", '&prime')))[1:]
    226227            yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
    227                 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag))
     228                (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s, %s); return false;"' % (result_id or '', result_name)), conditional_escape(result_repr), table_tag))
    228229        else:
    229230            yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr)))
    230231
  • django/contrib/admin/widgets.py

     
    121121        output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \
    122122            (related_url, url, name))
    123123        output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="%s" /></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Lookup')))
    124         if value:
    125             output.append(self.label_for_value(value))
     124        #if value:
     125        #    output.append(self.label_for_value(value))
     126        output.append(self.label_for_value(value, "id_%s" % name))
    126127        return mark_safe(u''.join(output))
    127128   
    128129    def base_url_parameters(self):
     
    149150        obj = self.rel.to.objects.get(**{key: value})
    150151        return '&nbsp;<strong>%s</strong>' % truncate_words(obj, 14)
    151152
     153    def label_for_value(self, value, name=''):
     154        # Placeholder used to display description during insertion
     155        if value:
     156            key = self.rel.get_related_field().name
     157            obj = self.rel.to.objects.get(**{key: value})
     158        else:
     159            obj = ''
     160        return '&nbsp;<strong id="view_lookup_%s">%s</strong>' % \
     161                    (name, truncate_words(obj, 14))
     162
    152163class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
    153164    """
    154165    A Widget for displaying ManyToMany ids in the "raw_id" interface rather than
     
    168179    def url_parameters(self):
    169180        return self.base_url_parameters()
    170181   
    171     def label_for_value(self, value):
     182    def label_for_value(self, value, nome=''):
    172183        return ''
    173184
    174185    def value_from_datadict(self, data, files, name):
Back to Top