From 85fb2083bbfd9ce4251d89dbe23471d7bc39c936 Mon Sep 17 00:00:00 2001 From: Brent O'Connor Date: Fri, 24 Aug 2012 13:57:48 -0700 Subject: [PATCH 1/3] Made updates so django-categories works with django-grappelli --- .../editor/static/editor/jquery.treeTable.css | 4 ++ .../templates/admin/editor/tree_editor.html | 59 +++++++++---------- .../admin/editor/tree_list_results.html | 44 +++++++------- 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/categories/editor/static/editor/jquery.treeTable.css b/categories/editor/static/editor/jquery.treeTable.css index f9fccd9..9d9a263 100644 --- a/categories/editor/static/editor/jquery.treeTable.css +++ b/categories/editor/static/editor/jquery.treeTable.css @@ -14,6 +14,10 @@ zoom: 1; /* IE7 Hack */ } + +.treeTable td.action-checkbox, .treeTable th.action-checkbox-column { + padding-left: 20px; +} .treeTable tr.collapsed td .expander { background-image: url(toggle-expand-dark.png); } diff --git a/categories/editor/templates/admin/editor/tree_editor.html b/categories/editor/templates/admin/editor/tree_editor.html index dc1fa02..34da30e 100644 --- a/categories/editor/templates/admin/editor/tree_editor.html +++ b/categories/editor/templates/admin/editor/tree_editor.html @@ -1,39 +1,38 @@ {% extends "admin/change_list.html" %} {% load adminmedia admin_list i18n admin_tree_list %} {% block extrahead %} - {{block.super}} - + treeTable = $("#result_list").treeTable({initialState : "{{ EDITOR_TREE_INITIAL_STATE }}"}); + else + treeTable = $("#result_list").treeTable({initialState : "expanded"}); + function toggleChildren(index, value) { + var row = value.parentNode.parentNode; + if (row.className.match(/child-of-node-\d+/)) { + value.checked = /child-of-node-(\d+)/.exec(row.className); + } + if($(row).hasClass("parent")) { + $("table.treeTable tbody tr.child-of-" + row.id + " input").each(toggleChildren); + } + $("tr input.action-select").actions(); + }; + $('.action-select').each( + function(){ + $(this).bind('click', function(event){ + // Get the tr from checkbox -> td -> tr + var row = event.currentTarget.parentNode.parentNode; + $("table.treeTable tbody tr.child-of-" + row.id + " input").each(toggleChildren); + }); + }); + }); + })(django.jQuery); + {% endblock %} {% block result_list %} - {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %} {% result_tree_list cl %} {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} {% endblock %} diff --git a/categories/editor/templates/admin/editor/tree_list_results.html b/categories/editor/templates/admin/editor/tree_list_results.html index 703bf45..379471e 100644 --- a/categories/editor/templates/admin/editor/tree_list_results.html +++ b/categories/editor/templates/admin/editor/tree_list_results.html @@ -1,24 +1,28 @@ {% if result_hidden_fields %} -
{# DIV for HTML validation #} -{% for item in result_hidden_fields %}{{ item }}{% endfor %} -
+
{# DIV for HTML validation #} + {% for item in result_hidden_fields %}{{ item }}{% endfor %} +
{% endif %} + {% if results %} -
- - - -{% for header in result_headers %} -{% if header.sortable %}{% endif %} -{{ header.text|capfirst }} -{% if header.sortable %}{% endif %}{% endfor %} - - - -{% for result in results %} -{% for item in result %}{{ item }}{% endfor %} -{% endfor %} - -
+
+ + + + {% for header in result_headers %} + + {% endfor %} + + + + {% for result in results %} + {% for item in result %}{{ item }}{% endfor %} + {% endfor %} + +
+ {% if header.sortable %}{% endif %} + {{ header.text|capfirst }} + {% if header.sortable %}{% endif %} +
-{% endif %} +{% endif %} \ No newline at end of file From ff6043d2b3f6c90db7c01178aac57f9175698f3d Mon Sep 17 00:00:00 2001 From: Brent O'Connor Date: Mon, 27 Aug 2012 09:45:26 -0700 Subject: [PATCH 2/3] Updated the code so it will work with or without Grappelli installed --- categories/editor/settings.py | 2 + .../admin/editor/grappelli_tree_editor.html | 38 +++++++++++++++++ .../editor/grappelli_tree_list_results.html | 28 +++++++++++++ .../templates/admin/editor/tree_editor.html | 5 ++- .../admin/editor/tree_list_results.html | 42 +++++++++---------- .../editor/templatetags/admin_tree_list.py | 8 +++- categories/editor/tree_editor.py | 11 +++-- 7 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 categories/editor/templates/admin/editor/grappelli_tree_editor.html create mode 100644 categories/editor/templates/admin/editor/grappelli_tree_list_results.html diff --git a/categories/editor/settings.py b/categories/editor/settings.py index 9f4658a..cd83e10 100644 --- a/categories/editor/settings.py +++ b/categories/editor/settings.py @@ -9,3 +9,5 @@ if STATIC_URL == None: MEDIA_PATH = getattr(settings, 'EDITOR_MEDIA_PATH', '%seditor/' % STATIC_URL) TREE_INITIAL_STATE = getattr(settings, 'EDITOR_TREE_INITIAL_STATE', 'collapsed') + +IS_GRAPPELLI_INSTALLED = True if 'grappelli' in settings.INSTALLED_APPS else False diff --git a/categories/editor/templates/admin/editor/grappelli_tree_editor.html b/categories/editor/templates/admin/editor/grappelli_tree_editor.html new file mode 100644 index 0000000..34da30e --- /dev/null +++ b/categories/editor/templates/admin/editor/grappelli_tree_editor.html @@ -0,0 +1,38 @@ +{% extends "admin/change_list.html" %} +{% load adminmedia admin_list i18n admin_tree_list %} +{% block extrahead %} + {{block.super}} + +{% endblock %} +{% block result_list %} + {% result_tree_list cl %} + {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} +{% endblock %} diff --git a/categories/editor/templates/admin/editor/grappelli_tree_list_results.html b/categories/editor/templates/admin/editor/grappelli_tree_list_results.html new file mode 100644 index 0000000..379471e --- /dev/null +++ b/categories/editor/templates/admin/editor/grappelli_tree_list_results.html @@ -0,0 +1,28 @@ +{% if result_hidden_fields %} +
{# DIV for HTML validation #} + {% for item in result_hidden_fields %}{{ item }}{% endfor %} +
+{% endif %} + +{% if results %} +
+ + + + {% for header in result_headers %} + + {% endfor %} + + + + {% for result in results %} + {% for item in result %}{{ item }}{% endfor %} + {% endfor %} + +
+ {% if header.sortable %}{% endif %} + {{ header.text|capfirst }} + {% if header.sortable %}{% endif %} +
+
+{% endif %} \ No newline at end of file diff --git a/categories/editor/templates/admin/editor/tree_editor.html b/categories/editor/templates/admin/editor/tree_editor.html index 34da30e..08b7d2f 100644 --- a/categories/editor/templates/admin/editor/tree_editor.html +++ b/categories/editor/templates/admin/editor/tree_editor.html @@ -5,7 +5,7 @@ {% endblock %} {% block result_list %} + {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %} {% result_tree_list cl %} {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/categories/editor/templates/admin/editor/tree_list_results.html b/categories/editor/templates/admin/editor/tree_list_results.html index 379471e..e5f1784 100644 --- a/categories/editor/templates/admin/editor/tree_list_results.html +++ b/categories/editor/templates/admin/editor/tree_list_results.html @@ -1,28 +1,24 @@ {% if result_hidden_fields %} -
{# DIV for HTML validation #} - {% for item in result_hidden_fields %}{{ item }}{% endfor %} -
+
{# DIV for HTML validation #} +{% for item in result_hidden_fields %}{{ item }}{% endfor %} +
{% endif %} - {% if results %} -
- - - - {% for header in result_headers %} - - {% endfor %} - - - - {% for result in results %} - {% for item in result %}{{ item }}{% endfor %} - {% endfor %} - -
- {% if header.sortable %}{% endif %} - {{ header.text|capfirst }} - {% if header.sortable %}{% endif %} -
+
+ + + +{% for header in result_headers %} +{% if header.sortable %}{% endif %} +{{ header.text|capfirst }} +{% if header.sortable %}{% endif %}{% endfor %} + + + +{% for result in results %} +{% for item in result %}{{ item }}{% endfor %} +{% endfor %} + +
{% endif %} \ No newline at end of file diff --git a/categories/editor/templatetags/admin_tree_list.py b/categories/editor/templatetags/admin_tree_list.py index 61ff5dd..658bd41 100644 --- a/categories/editor/templatetags/admin_tree_list.py +++ b/categories/editor/templatetags/admin_tree_list.py @@ -12,8 +12,14 @@ from django.utils.encoding import smart_unicode, force_unicode from django.utils.html import escape, conditional_escape from django.utils.safestring import mark_safe +from categories.editor import settings + register = Library() +TREE_LIST_RESULTS_TEMPLATE = 'admin/editor/tree_list_results.html' +if settings.IS_GRAPPELLI_INSTALLED: + TREE_LIST_RESULTS_TEMPLATE = 'admin/editor/grappelli_tree_list_results.html' + def items_for_tree_result(cl, result, form): """ @@ -145,4 +151,4 @@ def result_tree_list(cl): from django.contrib.admin.templatetags.admin_list import result_hidden_fields result['result_hidden_fields'] = list(result_hidden_fields(cl)) return result -result_tree_list = register.inclusion_tag("admin/editor/tree_list_results.html")(result_tree_list) +result_tree_list = register.inclusion_tag(TREE_LIST_RESULTS_TEMPLATE)(result_tree_list) diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index bb43ac4..87855e7 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -104,10 +104,15 @@ class TreeEditor(admin.ModelAdmin): self.list_display.remove('action_checkbox') opts = self.model._meta + + grappelli_prefix = "" + if settings.IS_GRAPPELLI_INSTALLED: + grappelli_prefix = "grappelli_" + self.change_list_template = [ - 'admin/%s/%s/editor/tree_editor.html' % (opts.app_label, opts.object_name.lower()), - 'admin/%s/editor/tree_editor.html' % opts.app_label, - 'admin/editor/tree_editor.html', + 'admin/%s/%s/editor/%stree_editor.html' % (opts.app_label, opts.object_name.lower(), grappelli_prefix), + 'admin/%s/editor/%stree_editor.html' % (opts.app_label, grappelli_prefix), + 'admin/editor/%stree_editor.html' % grappelli_prefix, ] def get_changelist(self, request, **kwargs): From 8a621e9d145be2b187ccd09bd6a96e421cc5ea4e Mon Sep 17 00:00:00 2001 From: Brent O'Connor Date: Mon, 27 Aug 2012 16:56:12 -0700 Subject: [PATCH 3/3] Simplified the assignment of the IS_GRAPPELLI_INSTALLED variable --- categories/editor/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/categories/editor/settings.py b/categories/editor/settings.py index cd83e10..399142b 100644 --- a/categories/editor/settings.py +++ b/categories/editor/settings.py @@ -10,4 +10,4 @@ MEDIA_PATH = getattr(settings, 'EDITOR_MEDIA_PATH', '%seditor/' % STATIC_URL) TREE_INITIAL_STATE = getattr(settings, 'EDITOR_TREE_INITIAL_STATE', 'collapsed') -IS_GRAPPELLI_INSTALLED = True if 'grappelli' in settings.INSTALLED_APPS else False +IS_GRAPPELLI_INSTALLED = 'grappelli' in settings.INSTALLED_APPS