Ticket #7028: improved-raw-id-admin-feedback-fixed-insertion.diff
File improved-raw-id-admin-feedback-fixed-insertion.diff, 3.4 KB (added by , 17 years ago) |
---|
-
contrib/admin/media/js/admin/RelatedObjectLookups.js
26 26 return false; 27 27 } 28 28 29 function dismissRelatedLookupPopup(win, chosenId ) {29 function dismissRelatedLookupPopup(win, chosenId, chosenName) { 30 30 var name = win.name.replace(/___/g, '.'); 31 31 var elem = document.getElementById(name); 32 var nameElem = document.getElementById("view_lookup_" + name); 32 33 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { 33 34 elem.value += ',' + chosenId; 34 35 } else { 35 36 document.getElementById(name).value = chosenId; 36 37 } 38 if(nameElem) { 39 nameElem.innerHTML = chosenName; 40 } 37 41 win.close(); 38 42 } 39 43 -
contrib/admin/templatetags/admin_list.py
196 196 # Convert the pk to something that can be used in Javascript. 197 197 # Problem cases are long ints (23L) and non-ASCII strings. 198 198 result_id = repr(force_unicode(getattr(result, pk)))[1:] 199 result_name = repr(force_unicode(result))[1:] 199 200 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)) 201 202 else: 202 203 yield mark_safe(u'<td%s>%s</td>' % (row_class, conditional_escape(result_repr))) 203 204 -
contrib/admin/widgets.py
101 101 output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \ 102 102 (related_url, url, name)) 103 103 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)) 106 107 return mark_safe(u''.join(output)) 107 108 108 def label_for_value(self, value): 109 return ' <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 ' <strong id="view_lookup_%s">%s</strong>' % \ 116 (name, truncate_words(value, 14)) 111 117 112 118 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): 113 119 """