From 56b99aaf661dfa9cee4ab13ba8aaa7c35635902d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Tue, 23 Jan 2024 16:46:42 +0100 Subject: [PATCH] remove code for obsolete Django versions, remove support for Django 2.0 --- categories/editor/settings.py | 3 - .../templatetags/admin_tree_list_tags.py | 25 +-------- categories/editor/tree_editor.py | 56 ++----------------- tox.ini | 9 ++- 4 files changed, 9 insertions(+), 84 deletions(-) diff --git a/categories/editor/settings.py b/categories/editor/settings.py index 164cf21..fd2c144 100644 --- a/categories/editor/settings.py +++ b/categories/editor/settings.py @@ -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 diff --git a/categories/editor/templatetags/admin_tree_list_tags.py b/categories/editor/templatetags/admin_tree_list_tags.py index b06001a..4632484 100644 --- a/categories/editor/templatetags/admin_tree_list_tags.py +++ b/categories/editor/templatetags/admin_tree_list_tags.py @@ -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(" ") # 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 diff --git a/categories/editor/tree_editor.py b/categories/editor/tree_editor.py index 586f248..2673c00 100644 --- a/categories/editor/tree_editor.py +++ b/categories/editor/tree_editor.py @@ -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( diff --git a/tox.ini b/tox.ini index ae65044..8c9d255 100644 --- a/tox.ini +++ b/tox.ini @@ -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