diff --git a/categories/editor/templatetags/admin_tree_list.py b/categories/editor/templatetags/admin_tree_list.py index cd20256..61ff5dd 100644 --- a/categories/editor/templatetags/admin_tree_list.py +++ b/categories/editor/templatetags/admin_tree_list.py @@ -1,6 +1,7 @@ +import django from django.db import models from django.template import Library -from django.contrib.admin.templatetags.admin_list import result_headers +from django.contrib.admin.templatetags.admin_list import result_headers, _boolean_icon try: from django.contrib.admin.util import lookup_field, display_for_field, label_for_field except ImportError: @@ -13,6 +14,7 @@ from django.utils.safestring import mark_safe register = Library() + def items_for_tree_result(cl, result, form): """ Generates the actual list of data. @@ -27,6 +29,9 @@ def items_for_tree_result(cl, result, form): result_repr = EMPTY_CHANGELIST_VALUE else: if f is None: + if django.VERSION[1] == 4: + if field_name == 'action_checkbox': + row_class = ' class="action-checkbox disclosure"' allow_tags = getattr(attr, 'allow_tags', False) boolean = getattr(attr, 'boolean', False) if boolean: @@ -50,21 +55,26 @@ def items_for_tree_result(cl, result, form): if isinstance(f, models.DateField) or isinstance(f, models.TimeField): row_class = ' class="nowrap"' if first: - try: - f, attr, checkbox_value = lookup_field('action_checkbox', result, cl.model_admin) - #result_repr = mark_safe("%s%s" % (value, result_repr)) - if row_class: - row_class = "%s%s" % (row_class[:-1],' disclosure"') - else: - row_class = ' class="disclosure"' - except (AttributeError, ObjectDoesNotExist): - pass - + if django.VERSION[1] < 4: + try: + f, attr, checkbox_value = lookup_field('action_checkbox', result, cl.model_admin) + #result_repr = mark_safe("%s%s" % (value, result_repr)) + if row_class: + row_class = "%s%s" % (row_class[:-1], ' disclosure"') + else: + row_class = ' class="disclosure"' + except (AttributeError, ObjectDoesNotExist): + pass + if force_unicode(result_repr) == '': result_repr = mark_safe(' ') # If list_display_links not defined, add the link tag to the first field if (first and not cl.list_display_links) or field_name in cl.list_display_links: - table_tag = 'td' #{True:'th', False:'td'}[first] + if django.VERSION[1] < 4: + table_tag = 'td' # {True:'th', False:'td'}[first] + else: + table_tag = {True:'th', False:'td'}[first] + url = cl.url_for_result(result) # Convert the pk to something that can be used in Javascript. # Problem cases are long ints (23L) and non-ASCII strings. @@ -75,8 +85,13 @@ def items_for_tree_result(cl, result, form): value = result.serializable_value(attr) result_id = repr(force_unicode(value))[1:] first = False - yield mark_safe(u'<%s%s>%s%s' % \ - (table_tag, row_class, checkbox_value, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag)) + if django.VERSION[1] < 4: + yield mark_safe(u'<%s%s>%s%s' % \ + (table_tag, row_class, checkbox_value, url, (cl.is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), conditional_escape(result_repr), table_tag)) + else: + yield mark_safe(u'<%s%s>%s' % \ + (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)) + else: # By default the fields come from ModelAdmin.list_editable, but if we pull # the fields out of the form instead of list_editable custom admins @@ -90,9 +105,11 @@ def items_for_tree_result(cl, result, form): if form and not form[cl.model._meta.pk.name].is_hidden: yield mark_safe(u'%s' % force_unicode(form[cl.model._meta.pk.name])) + class TreeList(list): pass + def tree_results(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): @@ -115,6 +132,7 @@ def tree_results(cl): res.parent_pk = None yield result + def result_tree_list(cl): """ Displays the headers and data list together diff --git a/example/settings.py b/example/settings.py index 9efef90..012dab6 100644 --- a/example/settings.py +++ b/example/settings.py @@ -1,5 +1,7 @@ # Django settings for sample project. -import os, sys +import os +import sys +import django APP = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) PROJ_ROOT = os.path.abspath(os.path.dirname(__file__)) @@ -75,11 +77,6 @@ STATICFILES_FINDERS = ( # 'django.contrib.staticfiles.finders.DefaultStorageFinder', ) -# URL prefix for admin static files -- CSS, JavaScript and images. -# Make sure to use a trailing slash. -# Examples: "http://foo.com/static/admin/", "/static/admin/". -ADMIN_MEDIA_PREFIX = '/static/admin/' - # Make this unique, and don't share it with anybody. SECRET_KEY = 'bwq#m)-zsey-fs)0#4*o=2z(v5g!ei=zytl9t-1hesh4b&-u^d' @@ -106,37 +103,27 @@ TEMPLATE_DIRS = ( os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')), ) -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.flatpages', - 'categories', - 'categories.editor', - 'mptt', - 'simpletext', - 'south', -) CATEGORIES_SETTINGS = { 'ALLOW_SLUG_CHANGE': True, - 'RELATION_MODELS': ['simpletext.simpletext','flatpages.flatpage'], + 'RELATION_MODELS': ['simpletext.simpletext', 'flatpages.flatpage'], 'FK_REGISTRY': { 'flatpages.flatpage': 'category', 'simpletext.simpletext': ( - 'primary_category', + 'primary_category', {'name': 'secondary_category', 'related_name': 'simpletext_sec_cat'}, ), }, 'M2M_REGISTRY': { 'simpletext.simpletext': {'name': 'categories', 'related_name': 'm2mcats'}, 'flatpages.flatpage': ( - {'name': 'other_categories', 'related_name': 'other_cats'}, - {'name': 'more_categories', 'related_name': 'more_cats'}, + {'name': 'other_categories', 'related_name': 'other_cats'}, + {'name': 'more_categories', 'related_name': 'more_cats'}, ), }, } + +if django.VERSION[1] == 4: + from settings14 import * +if django.VERSION[1] == 3: + from settings13 import * diff --git a/example/settings13.py b/example/settings13.py new file mode 100644 index 0000000..25145b1 --- /dev/null +++ b/example/settings13.py @@ -0,0 +1,16 @@ +ADMIN_MEDIA_PREFIX = '/static/admin/' + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.staticfiles', + 'django.contrib.flatpages', + 'categories', + 'categories.editor', + 'mptt', + 'simpletext', + # 'south', +) diff --git a/example/settings14.py b/example/settings14.py new file mode 100644 index 0000000..0c9163f --- /dev/null +++ b/example/settings14.py @@ -0,0 +1,15 @@ +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.flatpages', + 'categories', + 'categories.editor', + 'mptt', + 'simpletext', + # 'south', +)