remove code for obsolete Django versions, remove support for Django 2.0

This commit is contained in:
Petr Dlouhý 2024-01-23 16:46:42 +01:00
parent fc489a8d98
commit 82cef8fe7c
4 changed files with 9 additions and 84 deletions

View file

@ -1,9 +1,6 @@
"""Settings management for the editor."""
import django
from django.conf import settings
DJANGO10_COMPAT = django.VERSION[0] < 1 or (django.VERSION[0] == 1 and django.VERSION[1] < 1)
STATIC_URL = getattr(settings, "STATIC_URL", settings.MEDIA_URL)
if STATIC_URL is None:
STATIC_URL = settings.MEDIA_URL

View file

@ -1,5 +1,4 @@
"""Template tags used to render the tree editor."""
import django
from django.contrib.admin.templatetags.admin_list import _boolean_icon, result_headers
from django.contrib.admin.utils import lookup_field
from django.core.exceptions import ObjectDoesNotExist
@ -44,9 +43,6 @@ def items_for_tree_result(cl, result, form):
result_repr = get_empty_value_display(cl)
else:
if f is None:
if django.VERSION[0] == 1 and 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:
@ -69,25 +65,12 @@ def items_for_tree_result(cl, result, form):
result_repr = display_for_field(value, f, "")
if isinstance(f, models.DateField) or isinstance(f, models.TimeField):
row_class = ' class="nowrap"'
if first:
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
try:
f, attr, checkbox_value = lookup_field("action_checkbox", result, cl.model_admin)
if row_class:
row_class = "%s%s" % (row_class[:-1], ' disclosure"')
else:
row_class = ' class="disclosure"'
except (AttributeError, ObjectDoesNotExist):
pass
if force_str(result_repr) == "":
result_repr = mark_safe("&nbsp;")
# 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:
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
table_tag = "td" # {True:'th', False:'td'}[first]
else:
table_tag = {True: "th", False: "td"}[first]
table_tag = {True: "th", False: "td"}[first]
url = cl.url_for_result(result)
# Convert the pk to something that can be used in Javascript.
@ -165,13 +148,7 @@ def result_tree_list(cl):
"""
Displays the headers and data list together.
"""
import django
result = {"cl": cl, "result_headers": list(result_headers(cl)), "results": list(tree_results(cl))}
if django.VERSION[0] == 1 and django.VERSION[1] > 2:
from django.contrib.admin.templatetags.admin_list import result_hidden_fields
result["result_hidden_fields"] = list(result_hidden_fields(cl))
return result

View file

@ -80,10 +80,7 @@ class TreeChangeList(ChangeList):
"""A change list for a tree."""
def _get_default_ordering(self):
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
return "", "" # ('tree_id', 'lft')
else:
return []
return []
def get_ordering(self, request=None, queryset=None):
"""
@ -98,10 +95,7 @@ class TreeChangeList(ChangeList):
Returns:
Either a tuple of empty strings or an empty list.
"""
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
return "", "" # ('tree_id', 'lft')
else:
return []
return []
def get_queryset(self, *args, **kwargs):
"""Return a queryset."""
@ -170,36 +164,7 @@ class TreeEditor(admin.ModelAdmin):
pass
try:
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
params = (
request,
self.model,
list_display,
self.list_display_links,
self.list_filter,
self.date_hierarchy,
self.search_fields,
self.list_select_related,
self.list_per_page,
self.list_editable,
self,
)
elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1):
params = (
request,
self.model,
list_display,
self.list_display_links,
self.list_filter,
self.date_hierarchy,
self.search_fields,
self.list_select_related,
self.list_per_page,
self.list_max_show_all,
self.list_editable,
self,
)
elif django.VERSION < (4, 0):
if django.VERSION < (4, 0):
params = (
request,
self.model,
@ -314,20 +279,7 @@ class TreeEditor(admin.ModelAdmin):
"actions_on_top": self.actions_on_top,
"actions_on_bottom": self.actions_on_bottom,
}
if django.VERSION[0] == 1 and django.VERSION[1] < 4:
context["root_path"] = self.admin_site.root_path
elif django.VERSION[0] == 1 or (django.VERSION[0] == 2 and django.VERSION[1] < 1):
selection_note_all = ngettext("%(total_count)s selected", "All %(total_count)s selected", cl.result_count)
context.update(
{
"module_name": force_str(opts.verbose_name_plural),
"selection_note": _("0 of %(cnt)s selected") % {"cnt": len(cl.result_list)},
"selection_note_all": selection_note_all % {"total_count": cl.result_count},
}
)
else:
context["opts"] = self.model._meta
context["opts"] = self.model._meta
context.update(extra_context or {})
return render(

View file

@ -1,10 +1,10 @@
[tox]
envlist =
begin
py36-lint
py{36,37}-django{2,21}
py{36,37,38,39}-django{22,3,31}
py{36,37,38,39,310}-django{32}
py37-lint
py{37}-django{21}
py{37,38,39}-django{22,3,31}
py{37,38,39,310}-django{32}
py{38,39,310}-django{40}
py{38,39,310,311}-django{41}
py{310,311,312}-django{42,50}
@ -12,7 +12,6 @@ envlist =
[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39