Ticket #13221: django.patch
File django.patch, 10.3 KB (added by , 15 years ago) |
---|
-
contrib/admin/media/css/widgets.css
diff -r -U 3 django.orig/contrib/admin/media/css/widgets.css django/contrib/admin/media/css/widgets.css
old new 504 504 border-top: 1px solid #ddd; 505 505 } 506 506 507 form .vManyToManyRawIdAdminField + strong > ul{ 508 display:inline-block; 509 margin-left:0px; 510 padding:0 5px 0 0; 511 } 512 513 .vForeignKeyRawIdAdminField + strong, .vManyToManyRawIdAdminField + strong ul li,.related-clear{ 514 cursor:pointer; 515 margin:0 2px; 516 } 517 518 strong:empty + a.related-clear {display:none;} -
contrib/admin/media/js/admin/RelatedObjectLookups.js
diff -r -U 3 django.orig/contrib/admin/media/js/admin/RelatedObjectLookups.js django/contrib/admin/media/js/admin/RelatedObjectLookups.js
old new 41 41 return false; 42 42 } 43 43 44 function dismissRelatedLookupPopup(win, chosenId) { 44 function dismissRelatedLookupPopup(win, chosenId, choosenRepr) { 45 if(choosenRepr == null) 46 choosenRepr = choosenId; 45 47 var name = windowname_to_id(win.name); 46 48 var elem = document.getElementById(name); 47 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { 49 var display = elem; 50 while (display.tagName != 'STRONG') 51 display = display.nextElementSibling; 52 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1) { 48 53 elem.value += ',' + chosenId; 54 var li = document.createElement('LI') 55 if( li.attachEvent ) { 56 li.attachEvent('onclick', 'go_to(this,'+chosenId+')'); 57 } else { 58 li.setAttribute('onclick', 'go_to(this,'+chosenId+')'); 59 } 60 li.innerHTML = choosenRepr+'<a class="related-clear" onclick="return clear_related(this,'+chosenId+')">X</a>'; 61 for (var i = 0; i < display.childNodes.length; i++) 62 if (display.childNodes[i].tagName == 'UL') 63 display.childNodes[i].appendChild(li); 49 64 } else { 50 document.getElementById(name).value = chosenId; 65 elem.value = chosenId; 66 display.innerHTML = choosenRepr; 67 display.className = display.className; 51 68 } 52 69 win.close(); 53 70 } … … 73 90 newRepr = html_unescape(newRepr); 74 91 var name = windowname_to_id(win.name); 75 92 var elem = document.getElementById(name); 93 var display = elem; 94 while(display.tagName != 'STRONG') 95 display = display.nextElementSibling; 76 96 if (elem) { 77 97 if (elem.nodeName == 'SELECT') { 78 98 var o = new Option(newRepr, newId); 79 99 elem.options[elem.options.length] = o; 80 100 o.selected = true; 81 101 } else if (elem.nodeName == 'INPUT') { 82 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {102 if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1) { 83 103 elem.value += ',' + newId; 104 var li = document.createElement('LI') 105 if( li.attachEvent ) { 106 li.attachEvent('onclick', 'go_to(this,'+newId+')'); 107 } else { 108 li.setAttribute('onclick', 'go_to(this,'+newId+')'); 109 } 110 li.innerHTML = newRepr+'<a class="related-clear" onclick="return clear_related(this,'+newId+')">X</a>'; 111 for (var i = 0; i < display.childNodes.length; i++) 112 if (display.childNodes[i].tagName == 'UL') { 113 display.childNodes[i].appendChild(li); 114 break; 115 } 84 116 } else { 85 117 elem.value = newId; 118 display.innerHTML = newRepr; 119 display.className = display.className; 86 120 } 87 121 } 88 122 } else { … … 94 128 } 95 129 win.close(); 96 130 } 131 132 function go_to(el,id){ 133 if (id == null) { 134 while(el.tagName != 'INPUT') 135 el = el.previousElementSibling; 136 id = el.value; 137 } else 138 el = el.parentNode.parentNode; 139 if ( id ) { 140 while( el.className.indexOf('related-lookup') == -1 ) 141 el = el.nextElementSibling; 142 window.open(el.href.replace(/\?.*/,'')+id+'/', '_blank'); 143 } 144 } 145 146 function clear_related(el,id){ 147 if ( id ){ 148 el=el.parentNode; 149 while(el.tagName != 'LI') 150 el = el.parentNode; 151 var tg = el.parentNode; 152 tg.removeChild(el); 153 while(tg.tagName != 'STRONG') 154 tg = tg.parentNode; 155 while(tg.tagName != 'INPUT') 156 tg = tg.previousElementSibling; 157 tg.value = clear_ids(tg.value.replace(id,'','g').split(',')); 158 } else { 159 while(el.tagName != 'STRONG') 160 el = el.previousElementSibling; 161 el.innerHTML = ''; 162 el.className = el.className; 163 while(el.tagName != 'INPUT') 164 el = el.previousElementSibling; 165 el.value = ''; 166 } 167 } 168 169 function clear_ids(list){ 170 var new_list = []; 171 for(var i in list) 172 if (list[i] && new_list.indexOf(list[i]) == -1) 173 new_list.push(list[i]); 174 return new_list; 175 } -
contrib/admin/options.py
diff -r -U 3 django.orig/contrib/admin/options.py django/contrib/admin/options.py
old new 522 522 for formset in formsets: 523 523 for added_object in formset.new_objects: 524 524 change_message.append(_('Added %(name)s "%(object)s".') 525 % {'name': added_object._meta.verbose_name,525 % {'name': force_unicode(added_object._meta.verbose_name), 526 526 'object': force_unicode(added_object)}) 527 527 for changed_object, changed_fields in formset.changed_objects: 528 528 change_message.append(_('Changed %(list)s for %(name)s "%(object)s".') 529 529 % {'list': get_text_list(changed_fields, _('and')), 530 'name': changed_object._meta.verbose_name,530 'name': force_unicode(changed_object._meta.verbose_name), 531 531 'object': force_unicode(changed_object)}) 532 532 for deleted_object in formset.deleted_objects: 533 533 change_message.append(_('Deleted %(name)s "%(object)s".') 534 % {'name': deleted_object._meta.verbose_name,534 % {'name': force_unicode(deleted_object._meta.verbose_name), 535 535 'object': force_unicode(deleted_object)}) 536 536 change_message = ' '.join(change_message) 537 537 return change_message or _('No fields changed.') -
contrib/admin/templatetags/admin_list.py
diff -r -U 3 django.orig/contrib/admin/templatetags/admin_list.py django/contrib/admin/templatetags/admin_list.py
old new 225 225 value = result.serializable_value(attr) 226 226 result_id = repr(force_unicode(value))[1:] 227 227 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))228 (table_tag, row_class, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s, \'%s\'); return false;"' % (result_id or '',escape(result))), conditional_escape(result), table_tag)) 229 229 else: 230 230 # By default the fields come from ModelAdmin.list_editable, but if we pull 231 231 # the fields out of the form instead of list_editable custom admins -
contrib/admin/widgets.py
diff -r -U 3 django.orig/contrib/admin/widgets.py django/contrib/admin/widgets.py
old new 117 117 url = '' 118 118 if not attrs.has_key('class'): 119 119 attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript looks for this hook. 120 attrs['readonly'] = 1 120 121 output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)] 122 if value: 123 tvalue = self.value_for_label(value) 124 else: 125 tvalue = '' 126 output.append(self.label_for_tvalue(tvalue)) 121 127 # TODO: "id_" is hard-coded here. This should instead use the correct 122 128 # API to determine the ID dynamically. 123 129 output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \ 124 130 (related_url, url, name)) 125 131 output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="%s" /></a>' % (settings.ADMIN_MEDIA_PREFIX, _('Lookup'))) 126 if value:127 output.append(self.label_for_value(value))128 132 return mark_safe(u''.join(output)) 129 133 130 134 def base_url_parameters(self): … … 146 150 params.update({TO_FIELD_VAR: self.rel.get_related_field().name}) 147 151 return params 148 152 149 def label_for_value(self, value):153 def value_for_label(self, value): 150 154 key = self.rel.get_related_field().name 151 155 obj = self.rel.to._default_manager.get(**{key: value}) 152 return ' <strong>%s</strong>' % escape(truncate_words(obj, 14)) 156 return escape(truncate_words(obj, 14)) 157 158 def label_for_tvalue(self, tvalue): 159 return ' <strong onClick="go_to(this);">%s</strong><a class="related-clear" onclick="return clear_related(this)" title="%s">X</a>' % (tvalue,_('Clear')) 153 160 154 161 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): 155 162 """ … … 170 177 def url_parameters(self): 171 178 return self.base_url_parameters() 172 179 173 def label_for_value(self, value): 174 return '' 180 def value_for_label(self, value): 181 result = '' 182 key = self.rel.get_related_field().name 183 for i in value.split(','): 184 obj = self.rel.to._default_manager.get(**{key: int(i)}) 185 result += '<li onClick="go_to(this,%s);"><a class="related-clear" onclick="return clear_related(this,%s)" title="%s">X</a></li>' %(i,escape(truncate_words(obj, 14)),i,_('Clear')) 186 return result 187 188 def label_for_tvalue(self, tvalue): 189 return ' <strong><ul>%s</ul></strong>' % tvalue 175 190 176 191 def value_from_datadict(self, data, files, name): 177 192 value = data.get(name, None)