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

File improved-raw-id-admin-django-1.0.1.2.diff, 3.8 KB (added by marcob, 16 years ago)

patch for django 1.1.0 alpha

  • django/contrib/admin/media/js/admin/RelatedObjectLookups.js

     
    4141    return false;
    4242}
    4343
    44 function dismissRelatedLookupPopup(win, chosenId) {
     44function dismissRelatedLookupPopup(win, chosenId, chosenName) {
    4545    var name = windowname_to_id(win.name);
    4646    var elem = document.getElementById(name);
     47    var nameElem = document.getElementById("view_lookup_" + name);
     48
    4749    if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
    4850        elem.value += ',' + chosenId;
    4951    } else {
    5052        document.getElementById(name).value = chosenId;
    5153    }
     54    if(nameElem) {
     55      nameElem.innerHTML = chosenName;
     56    }
    5257    win.close();
    5358}
    5459
  • django/contrib/admin/templatetags/admin_list.py

     
    223223            else:
    224224                attr = pk
    225225            value = result.serializable_value(attr)
    226226            result_id = repr(force_unicode(value))[1:]
     227            result_name = repr(escape(force_unicode(result_id).replace("'", '&prime')))[1:]
    227228            yield mark_safe(u'<%s%s><a href="%s"%s>%s</a></%s>' % \
    228                 (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))
     229                (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))
    229230        else:
    230231            yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr)))
    231232
  • 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._default_manager.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