Ticket #4134: django-0.96-contrib-admin-raw_id_admin-repr_on_select_change.diff

File django-0.96-contrib-admin-raw_id_admin-repr_on_select_change.diff, 2.5 KB (added by anonymous, 8 years ago)
  • media/js/admin/RelatedObjectLookups.js

     
    1111    } else {
    1212        href = triggeringLink.href + '?pop=1';
    1313    }
    14     var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
     14    var win = window.open(href, name, 'height=500,width=1000,resizable=yes,scrollbars=yes');
    1515    win.focus();
    1616    return false;
    1717}
    1818
    19 function dismissRelatedLookupPopup(win, chosenId) {
     19function dismissRelatedLookupPopup(win, chosenId, chosenRepr) {
    2020    var name = win.name.replace(/___/g, '.');
    2121    var elem = document.getElementById(name);
    2222    if (elem.className.indexOf('vRawIdAdminField') != -1 && elem.value) {
    2323        elem.value += ',' + chosenId;
    2424    } else {
    25         document.getElementById(name).value = chosenId;
     25        var node = document.getElementById(name);
     26        var parentNode = node.parentNode;
     27        var strongNodes = parentNode.getElementsByTagName("strong");
     28        node.value = chosenId;
     29        if (strongNodes.length==1) {
     30            // change repr
     31            strongNodes[0].innerHTML = chosenRepr;
     32        } else if (strongNodes.length==0) {
     33            // add repr
     34            var strong = document.createElement("strong");
     35            strong.innerHTML = chosenRepr;
     36            parentNode.appendChild(strong);
     37        }
    2638    }
    2739    win.close();
    2840}
  • templatetags/admin_list.py

     
    88from django.utils.text import capfirst
    99from django.utils.translation import get_date_formats, get_partial_date_formats
    1010from django.template import Library
     11from django.template.defaultfilters import truncatewords
    1112import datetime
    1213
    1314register = Library()
     
    187188            url = cl.url_for_result(result)
    188189            result_id = str(getattr(result, pk)) # str() is needed in case of 23L (long ints)
    189190            yield ('<%s%s><a href="%s"%s>%s</a></%s>' % \
    190                 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr, table_tag))
     191                (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r, %r); return false;"' % (result_id or '', escape(truncatewords(result_repr,14)))), result_repr, table_tag))
    191192        else:
    192193            yield ('<td%s>%s</td>' % (row_class, result_repr))
    193194
Back to Top