From d7b49f5b0dcecfcc9b5a77632ecbba88e7637490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Thu, 13 Dec 2012 18:57:39 +0200 Subject: [PATCH] Fixed #19469 -- Removed opts.get_ordered_objects() and related code The code was dead-code since 2006. --- django/contrib/admin/options.py | 4 - .../admin/static/admin/js/admin/ordering.js | 137 -------------- .../static/admin/js/getElementsBySelector.js | 167 ------------------ .../admin/templates/admin/change_form.html | 2 +- .../admin/templates/admin/submit_line.html | 8 +- .../admin/templatetags/admin_modify.py | 2 - django/db/models/options.py | 13 -- 7 files changed, 5 insertions(+), 328 deletions(-) delete mode 100644 django/contrib/admin/static/admin/js/admin/ordering.js delete mode 100644 django/contrib/admin/static/admin/js/getElementsBySelector.js diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index f4c27511d3..1827d40159 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -408,8 +408,6 @@ class ModelAdmin(BaseModelAdmin): js.append('actions%s.js' % extra) if self.prepopulated_fields: js.extend(['urlify.js', 'prepopulate%s.js' % extra]) - if self.opts.get_ordered_objects(): - js.extend(['getElementsBySelector.js', 'dom-drag.js' , 'admin/ordering.js']) return forms.Media(js=[static('admin/js/%s' % url) for url in js]) def get_model_perms(self, request): @@ -764,7 +762,6 @@ class ModelAdmin(BaseModelAdmin): def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None): opts = self.model._meta app_label = opts.app_label - ordered_objects = opts.get_ordered_objects() context.update({ 'add': add, 'change': change, @@ -773,7 +770,6 @@ class ModelAdmin(BaseModelAdmin): 'has_delete_permission': self.has_delete_permission(request, obj), 'has_file_field': True, # FIXME - this should check if form or formsets have a FileField, 'has_absolute_url': hasattr(self.model, 'get_absolute_url'), - 'ordered_objects': ordered_objects, 'form_url': form_url, 'opts': opts, 'content_type_id': ContentType.objects.get_for_model(self.model).id, diff --git a/django/contrib/admin/static/admin/js/admin/ordering.js b/django/contrib/admin/static/admin/js/admin/ordering.js deleted file mode 100644 index 595be4d62b..0000000000 --- a/django/contrib/admin/static/admin/js/admin/ordering.js +++ /dev/null @@ -1,137 +0,0 @@ -addEvent(window, 'load', reorder_init); - -var lis; -var top = 0; -var left = 0; -var height = 30; - -function reorder_init() { - lis = document.getElementsBySelector('ul#orderthese li'); - var input = document.getElementsBySelector('input[name=order_]')[0]; - setOrder(input.value.split(',')); - input.disabled = true; - draw(); - // Now initialize the dragging behavior - var limit = (lis.length - 1) * height; - for (var i = 0; i < lis.length; i++) { - var li = lis[i]; - var img = document.getElementById('handle'+li.id); - li.style.zIndex = 1; - Drag.init(img, li, left + 10, left + 10, top + 10, top + 10 + limit); - li.onDragStart = startDrag; - li.onDragEnd = endDrag; - img.style.cursor = 'move'; - } -} - -function submitOrderForm() { - var inputOrder = document.getElementsBySelector('input[name=order_]')[0]; - inputOrder.value = getOrder(); - inputOrder.disabled=false; -} - -function startDrag() { - this.style.zIndex = '10'; - this.className = 'dragging'; -} - -function endDrag(x, y) { - this.style.zIndex = '1'; - this.className = ''; - // Work out how far along it has been dropped, using x co-ordinate - var oldIndex = this.index; - var newIndex = Math.round((y - 10 - top) / height); - // 'Snap' to the correct position - this.style.top = (10 + top + newIndex * height) + 'px'; - this.index = newIndex; - moveItem(oldIndex, newIndex); -} - -function moveItem(oldIndex, newIndex) { - // Swaps two items, adjusts the index and left co-ord for all others - if (oldIndex == newIndex) { - return; // Nothing to swap; - } - var direction, lo, hi; - if (newIndex > oldIndex) { - lo = oldIndex; - hi = newIndex; - direction = -1; - } else { - direction = 1; - hi = oldIndex; - lo = newIndex; - } - var lis2 = new Array(); // We will build the new order in this array - for (var i = 0; i < lis.length; i++) { - if (i < lo || i > hi) { - // Position of items not between the indexes is unaffected - lis2[i] = lis[i]; - continue; - } else if (i == newIndex) { - lis2[i] = lis[oldIndex]; - continue; - } else { - // Item is between the two indexes - move it along 1 - lis2[i] = lis[i - direction]; - } - } - // Re-index everything - reIndex(lis2); - lis = lis2; - draw(); -// document.getElementById('hiddenOrder').value = getOrder(); - document.getElementsBySelector('input[name=order_]')[0].value = getOrder(); -} - -function reIndex(lis) { - for (var i = 0; i < lis.length; i++) { - lis[i].index = i; - } -} - -function draw() { - for (var i = 0; i < lis.length; i++) { - var li = lis[i]; - li.index = i; - li.style.position = 'absolute'; - li.style.left = (10 + left) + 'px'; - li.style.top = (10 + top + (i * height)) + 'px'; - } -} - -function getOrder() { - var order = new Array(lis.length); - for (var i = 0; i < lis.length; i++) { - order[i] = lis[i].id.substring(1, 100); - } - return order.join(','); -} - -function setOrder(id_list) { - /* Set the current order to match the lsit of IDs */ - var temp_lis = new Array(); - for (var i = 0; i < id_list.length; i++) { - var id = 'p' + id_list[i]; - temp_lis[temp_lis.length] = document.getElementById(id); - } - reIndex(temp_lis); - lis = temp_lis; - draw(); -} - -function addEvent(elm, evType, fn, useCapture) -// addEvent and removeEvent -// cross-browser event handling for IE5+, NS6 and Mozilla -// By Scott Andrew -{ - if (elm.addEventListener){ - elm.addEventListener(evType, fn, useCapture); - return true; - } else if (elm.attachEvent){ - var r = elm.attachEvent("on"+evType, fn); - return r; - } else { - elm['on'+evType] = fn; - } -} diff --git a/django/contrib/admin/static/admin/js/getElementsBySelector.js b/django/contrib/admin/static/admin/js/getElementsBySelector.js deleted file mode 100644 index 15b57a1908..0000000000 --- a/django/contrib/admin/static/admin/js/getElementsBySelector.js +++ /dev/null @@ -1,167 +0,0 @@ -/* document.getElementsBySelector(selector) - - returns an array of element objects from the current document - matching the CSS selector. Selectors can contain element names, - class names and ids and can be nested. For example: - - elements = document.getElementsBySelect('div#main p a.external') - - Will return an array of all 'a' elements with 'external' in their - class attribute that are contained inside 'p' elements that are - contained inside the 'div' element which has id="main" - - New in version 0.4: Support for CSS2 and CSS3 attribute selectors: - See http://www.w3.org/TR/css3-selectors/#attribute-selectors - - Version 0.4 - Simon Willison, March 25th 2003 - -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows - -- Opera 7 fails -*/ - -function getAllChildren(e) { - // Returns all children of element. Workaround required for IE5/Windows. Ugh. - return e.all ? e.all : e.getElementsByTagName('*'); -} - -document.getElementsBySelector = function(selector) { - // Attempt to fail gracefully in lesser browsers - if (!document.getElementsByTagName) { - return new Array(); - } - // Split selector in to tokens - var tokens = selector.split(' '); - var currentContext = new Array(document); - for (var i = 0; i < tokens.length; i++) { - token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');; - if (token.indexOf('#') > -1) { - // Token is an ID selector - var bits = token.split('#'); - var tagName = bits[0]; - var id = bits[1]; - var element = document.getElementById(id); - if (!element || (tagName && element.nodeName.toLowerCase() != tagName)) { - // ID not found or tag with that ID not found, return false. - return new Array(); - } - // Set currentContext to contain just this element - currentContext = new Array(element); - continue; // Skip to next token - } - if (token.indexOf('.') > -1) { - // Token contains a class selector - var bits = token.split('.'); - var tagName = bits[0]; - var className = bits[1]; - if (!tagName) { - tagName = '*'; - } - // Get elements matching tag, filter them for class selector - var found = new Array; - var foundCount = 0; - for (var h = 0; h < currentContext.length; h++) { - var elements; - if (tagName == '*') { - elements = getAllChildren(currentContext[h]); - } else { - try { - elements = currentContext[h].getElementsByTagName(tagName); - } - catch(e) { - elements = []; - } - } - for (var j = 0; j < elements.length; j++) { - found[foundCount++] = elements[j]; - } - } - currentContext = new Array; - var currentContextIndex = 0; - for (var k = 0; k < found.length; k++) { - if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) { - currentContext[currentContextIndex++] = found[k]; - } - } - continue; // Skip to next token - } - // Code to deal with attribute selectors - if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) { - var tagName = RegExp.$1; - var attrName = RegExp.$2; - var attrOperator = RegExp.$3; - var attrValue = RegExp.$4; - if (!tagName) { - tagName = '*'; - } - // Grab all of the tagName elements within current context - var found = new Array; - var foundCount = 0; - for (var h = 0; h < currentContext.length; h++) { - var elements; - if (tagName == '*') { - elements = getAllChildren(currentContext[h]); - } else { - elements = currentContext[h].getElementsByTagName(tagName); - } - for (var j = 0; j < elements.length; j++) { - found[foundCount++] = elements[j]; - } - } - currentContext = new Array; - var currentContextIndex = 0; - var checkFunction; // This function will be used to filter the elements - switch (attrOperator) { - case '=': // Equality - checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); }; - break; - case '~': // Match one of space seperated words - checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); }; - break; - case '|': // Match start with value followed by optional hyphen - checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); }; - break; - case '^': // Match starts with value - checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); }; - break; - case '$': // Match ends with value - fails with "Warning" in Opera 7 - checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); }; - break; - case '*': // Match ends with value - checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); }; - break; - default : - // Just test for existence of attribute - checkFunction = function(e) { return e.getAttribute(attrName); }; - } - currentContext = new Array; - var currentContextIndex = 0; - for (var k = 0; k < found.length; k++) { - if (checkFunction(found[k])) { - currentContext[currentContextIndex++] = found[k]; - } - } - // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); - continue; // Skip to next token - } - // If we get here, token is JUST an element (not a class or ID selector) - tagName = token; - var found = new Array; - var foundCount = 0; - for (var h = 0; h < currentContext.length; h++) { - var elements = currentContext[h].getElementsByTagName(tagName); - for (var j = 0; j < elements.length; j++) { - found[foundCount++] = elements[j]; - } - } - currentContext = found; - } - return currentContext; -} - -/* That revolting regular expression explained -/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/ - \---/ \---/\-------------/ \-------/ - | | | | - | | | The value - | | ~,|,^,$,* or = - | Attribute - Tag -*/ diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 4962e732a2..48846960b3 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -9,7 +9,7 @@ {% block extrastyle %}{{ block.super }}{% endblock %} -{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %} +{% block coltype %}colM{% endblock %} {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %} diff --git a/django/contrib/admin/templates/admin/submit_line.html b/django/contrib/admin/templates/admin/submit_line.html index 8c9d22752d..38a97a1c6a 100644 --- a/django/contrib/admin/templates/admin/submit_line.html +++ b/django/contrib/admin/templates/admin/submit_line.html @@ -1,8 +1,8 @@ {% load i18n admin_urls %}
-{% if show_save %}{% endif %} +{% if show_save %}{% endif %} {% if show_delete_link %}{% endif %} -{% if show_save_as_new %}{%endif%} -{% if show_save_and_add_another %}{% endif %} -{% if show_save_and_continue %}{% endif %} +{% if show_save_as_new %}{%endif%} +{% if show_save_and_add_another %}{% endif %} +{% if show_save_and_continue %}{% endif %}
diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index f6ac59635a..cecc6ed6c4 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -30,8 +30,6 @@ def submit_row(context): save_as = context['save_as'] ctx = { 'opts': opts, - 'onclick_attrib': (opts.get_ordered_objects() and change - and 'onclick="submitOrderForm();"' or ''), 'show_delete_link': (not is_popup and context['has_delete_permission'] and change and context.get('show_delete', True)), 'show_save_as_new': not is_popup and change and save_as, diff --git a/django/db/models/options.py b/django/db/models/options.py index 4c8dfd83c5..f74d9ffff8 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -507,16 +507,3 @@ class Options(object): # of the chain to the ancestor is that parent # links return self.parents[parent] or parent_link - - def get_ordered_objects(self): - "Returns a list of Options objects that are ordered with respect to this object." - if not hasattr(self, '_ordered_objects'): - objects = [] - # TODO - #for klass in get_models(get_app(self.app_label)): - # opts = klass._meta - # if opts.order_with_respect_to and opts.order_with_respect_to.rel \ - # and self == opts.order_with_respect_to.rel.to._meta: - # objects.append(opts) - self._ordered_objects = objects - return self._ordered_objects