Ticket #7028: improved-raw-id-admin-feedback-fixed-regression-test.diff

File improved-raw-id-admin-feedback-fixed-regression-test.diff, 3.7 KB (added by Marcob <marcoberi@…>, 7 years ago)

This patch leaves only one (trivial) failure running django tests

  • 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);
    3233    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
    3334        elem.value += ',' + chosenId;
    3435    } else {
    3536        document.getElementById(name).value = chosenId;
    3637    }
     38    if(nameElem) {
     39      nameElem.innerHTML = chosenName;
     40    }
    3741    win.close();
    3842}
    3943
  • contrib/admin/templatetags/admin_list.py

     
    196196            # Convert the pk to something that can be used in Javascript.
    197197            # Problem cases are long ints (23L) and non-ASCII strings.
    198198            result_id = repr(force_unicode(getattr(result, pk)))[1:]
     199            result_name = repr(force_unicode(result))[1:]
    199200            yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
    200                 (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))
     201                (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))
    201202        else:
    202203            yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr)))
    203204
  • contrib/admin/widgets.py

     
    101101        output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \
    102102            (related_url, url, name))
    103103        output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX)
    104         if value:
    105             output.append(self.label_for_value(value))
     104        # TODO: "id_" is hard-coded here. This should instead use the correct
     105        # API to determine the ID dynamically.
     106        output.append(self.label_for_value(value, "id_%s" % name))
    106107        return mark_safe(u''.join(output))
    107108   
    108     def label_for_value(self, value):
    109         return '&nbsp;<strong>%s</strong>' % \
    110             truncate_words(self.rel.to.objects.get(pk=value), 14)
     109    def label_for_value(self, value, name=''):
     110        # Placeholder used to display description during insertion
     111        if value:
     112            value = self.rel.to.objects.get(pk=value)
     113        else:
     114            value = ''
     115        return '&nbsp;<strong id="view_lookup_%s">%s</strong>' % \
     116            (name, truncate_words(value, 14))
    111117           
    112118class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
    113119    """
     
    125131            value = ''
    126132        return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
    127133   
    128     def label_for_value(self, value):
     134    def label_for_value(self, value, nome=''):
    129135        return ''
    130136
    131137    def value_from_datadict(self, data, files, name):
Back to Top