From e65dd60c196ff1fe8c5d327677889d0925f4a011 Mon Sep 17 00:00:00 2001 From: raybittuiq Date: Wed, 27 Nov 2024 22:13:33 +0530 Subject: [PATCH 1/3] ran django-upgrades --- nested_admin/__init__.py | 5 +-- nested_admin/formsets.py | 12 ++--- nested_admin/nested.py | 15 +++---- nested_admin/polymorphic.py | 4 +- nested_admin/templatetags/nested_admin.py | 7 +-- nested_admin/tests/admin_widgets/tests.py | 5 ++- nested_admin/tests/nested_polymorphic/base.py | 12 ++--- .../test_polymorphic_std/models.py | 5 +-- nested_admin/tests/one_deep/tests.py | 3 +- nested_admin/tests/settings.py | 44 ++++++------------- .../tests/two_deep/test_permissions.py | 6 +-- nested_admin/tests/two_deep/tests.py | 2 - nested_admin/tests/urls.py | 11 ++--- nested_admin/urls.py | 4 +- nested_admin/views.py | 2 +- 15 files changed, 46 insertions(+), 91 deletions(-) diff --git a/nested_admin/__init__.py b/nested_admin/__init__.py index 4eea0a8c..88bd9101 100644 --- a/nested_admin/__init__.py +++ b/nested_admin/__init__.py @@ -121,10 +121,7 @@ def all_valid(original_all_valid, formsets): # Force Django to try to save the instance, # since we need it for the fk to work changed_data = parent_form.fields.keys() - if django.VERSION > (1, 9): - parent_form.__dict__['changed_data'] = changed_data - else: - parent_form._changed_data = changed_data + parent_form.__dict__['changed_data'] = changed_data if not hasattr(parent_form, 'parent_formset'): break parent_form.parent_formset._errors = None diff --git a/nested_admin/formsets.py b/nested_admin/formsets.py index 69a9b1e3..dc425e13 100644 --- a/nested_admin/formsets.py +++ b/nested_admin/formsets.py @@ -12,7 +12,7 @@ from six.moves import range if six.PY2: - from django.utils.encoding import force_text as force_str + from django.utils.encoding import force_str as force_str else: from django.utils.encoding import force_str @@ -196,10 +196,7 @@ def get_position(form): form.data[form.add_prefix(sort_field)] = six.text_type(i) # Force recalculation of changed_data - if django.VERSION > (1, 9): - form.__dict__.pop('changed_data', None) - else: - form._changed_data = None + form.__dict__.pop('changed_data', None) i += 1 @@ -298,10 +295,7 @@ def save_existing_objects(self, initial_forms=None, commit=True): form.data[form.add_prefix(pk_name)] = '' if not form.has_changed(): - if django.VERSION > (1, 9): - form.__dict__['changed_data'].append(pk_name) - else: - form._changed_data.append(pk_name) + form.__dict__['changed_data'].append(pk_name) saved_instances.extend(self.save_new_objects([form], commit)) continue diff --git a/nested_admin/nested.py b/nested_admin/nested.py index 83d9ab57..2eae337f 100644 --- a/nested_admin/nested.py +++ b/nested_admin/nested.py @@ -9,7 +9,7 @@ from django.urls import reverse except ImportError: # Django <= 1.9 - from django.core.urlresolvers import reverse + from django.urls import reverse from django.template.defaultfilters import capfirst import six from django.utils.functional import lazy @@ -52,13 +52,12 @@ def __init__(self, inline, *args, **kwargs): self.has_delete_permission = kwargs.pop('has_delete_permission', True) self.has_view_permission = kwargs.pop('has_view_permission', True) - if django.VERSION > (2, 1): - kwargs.update({ - 'has_add_permission': self.has_add_permission, - 'has_change_permission': self.has_change_permission, - 'has_delete_permission': self.has_delete_permission, - 'has_view_permission': self.has_view_permission, - }) + kwargs.update({ + 'has_add_permission': self.has_add_permission, + 'has_change_permission': self.has_change_permission, + 'has_delete_permission': self.has_delete_permission, + 'has_view_permission': self.has_view_permission, + }) super(NestedInlineAdminFormsetMixin, self).__init__(inline, *args, **kwargs) self.request = request diff --git a/nested_admin/polymorphic.py b/nested_admin/polymorphic.py index d93fd038..fa6ea37a 100644 --- a/nested_admin/polymorphic.py +++ b/nested_admin/polymorphic.py @@ -3,7 +3,7 @@ from django.conf import settings from django.contrib.admin import ModelAdmin -from django.utils.encoding import force_text +from django.utils.encoding import force_str from polymorphic.formsets import ( BasePolymorphicInlineFormSet, BasePolymorphicModelFormSet, BaseGenericPolymorphicInlineFormSet) @@ -114,7 +114,7 @@ def inline_formset_data(self): 'childTypes': [ { 'type': get_model_id(model), - 'name': force_text(model._meta.verbose_name), + 'name': force_str(model._meta.verbose_name), } for model in self.formset.child_forms.keys() ], }) diff --git a/nested_admin/templatetags/nested_admin.py b/nested_admin/templatetags/nested_admin.py index c321e7d8..a8eb8316 100644 --- a/nested_admin/templatetags/nested_admin.py +++ b/nested_admin/templatetags/nested_admin.py @@ -13,10 +13,7 @@ register = template.Library() -if django.VERSION >= (1, 10): - from django.templatetags.static import static as _static -else: - _static = None +from django.templatetags.static import static as _static django_version = django.VERSION[:2] @@ -27,7 +24,7 @@ def static(path): global _static if _static is None: if apps.is_installed('django-contrib.staticfiles'): - from django.contrib.staticfiles.templatetags.staticfiles import static as _static + from django.templatetags.static import static as _static else: from django.templatetags.static import static as _static if django.VERSION >= (1, 9) and path == 'admin/img/icon-unknown.gif': diff --git a/nested_admin/tests/admin_widgets/tests.py b/nested_admin/tests/admin_widgets/tests.py index f74bbd1f..58112e4e 100644 --- a/nested_admin/tests/admin_widgets/tests.py +++ b/nested_admin/tests/admin_widgets/tests.py @@ -5,7 +5,8 @@ import django from django.conf import settings import six -from django.utils.text import slugify, unescape_entities +import html +from django.utils.text import slugify from nested_admin.tests.base import ( expected_failure_if_suit, skip_if_not_grappelli, BaseNestedAdminTestCase) @@ -132,7 +133,7 @@ def check_fk(self, indexes): field_id = field.get_attribute('id') current_val = self.selenium.execute_script( 'return $("#%s").find("option:selected").html()' % field_id) - self.assertEqual(unescape_entities(current_val), name) + self.assertEqual(html.escape(current_val), name) class TestAdminWidgets(BaseWidgetTestCase): diff --git a/nested_admin/tests/nested_polymorphic/base.py b/nested_admin/tests/nested_polymorphic/base.py index e94b49d9..768ecf76 100644 --- a/nested_admin/tests/nested_polymorphic/base.py +++ b/nested_admin/tests/nested_polymorphic/base.py @@ -13,20 +13,16 @@ from polymorphic.models import PolymorphicModel except: # Temporary until django-polymorphic supports django 3.0 - if django.VERSION < (3, 0): - raise - else: - class PolymorphicModel(object): - pass + class PolymorphicModel(object): + pass class BaseNestedPolymorphicTestCase(BaseNestedAdminTestCase): @classmethod def setUpClass(cls): - if django.VERSION > (2, 2): - raise SkipTest( - 'django-polymorphic not yet compatible with Django 2.2 and 3.0') + raise SkipTest( + 'django-polymorphic not yet compatible with Django 2.2 and 3.0') if 'suit' in settings.INSTALLED_APPS: raise SkipTest('Skipping for django-suit') super(BaseNestedPolymorphicTestCase, cls).setUpClass() diff --git a/nested_admin/tests/nested_polymorphic/test_polymorphic_std/models.py b/nested_admin/tests/nested_polymorphic/test_polymorphic_std/models.py index 2359ed3b..1e6e684d 100644 --- a/nested_admin/tests/nested_polymorphic/test_polymorphic_std/models.py +++ b/nested_admin/tests/nested_polymorphic/test_polymorphic_std/models.py @@ -11,10 +11,7 @@ from polymorphic.models import PolymorphicModel except: # Temporary until django-polymorphic supports django 3.0 - if django.VERSION < (3, 0): - raise - else: - PolymorphicModel = models.Model + PolymorphicModel = models.Model @python_2_unicode_compatible diff --git a/nested_admin/tests/one_deep/tests.py b/nested_admin/tests/one_deep/tests.py index 6c942279..de78f556 100644 --- a/nested_admin/tests/one_deep/tests.py +++ b/nested_admin/tests/one_deep/tests.py @@ -78,8 +78,7 @@ def setUpClass(cls): if os.environ.get('TRAVIS_BUILD_NUMBER'): # For some reason these tests fail on travis when Django > 1.11 - if django.VERSION > (1, 11): - raise SkipTest("Issue with travis and Django >= 1.11") + raise SkipTest("Issue with travis and Django >= 1.11") cls.path_prefix = "travis_%s" % os.environ['TRAVIS_BUILD_NUMBER'] else: cls.path_prefix = "local" diff --git a/nested_admin/tests/settings.py b/nested_admin/tests/settings.py index efc8d331..609731cd 100644 --- a/nested_admin/tests/settings.py +++ b/nested_admin/tests/settings.py @@ -18,12 +18,11 @@ } SECRET_KEY = 'z-i*xqqn)r0i7leak^#clq6y5j8&tfslp^a4duaywj2$**s*0_' -if django.VERSION > (2, 0): - MIGRATION_MODULES = { - 'auth': None, - 'contenttypes': None, - 'sessions': None, - } +MIGRATION_MODULES = { + 'auth': None, + 'contenttypes': None, + 'sessions': None, +} try: import grappelli # noqa @@ -40,13 +39,6 @@ polymorphic = None -if django.VERSION < (3, 0): - try: - import polymorphic - except ImportError: - pass - else: - INSTALLED_APPS += ('polymorphic',) TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -99,23 +91,15 @@ os.path.basename(os.path.dirname(p))]) -if django.VERSION >= (1, 10): - MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - ] -else: - MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - ) +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] LOGGING = { 'version': 1, diff --git a/nested_admin/tests/two_deep/test_permissions.py b/nested_admin/tests/two_deep/test_permissions.py index bf2962f5..db71731f 100644 --- a/nested_admin/tests/two_deep/test_permissions.py +++ b/nested_admin/tests/two_deep/test_permissions.py @@ -9,7 +9,7 @@ try: from django.urls import reverse except ImportError: - from django.core.urlresolvers import reverse + from django.urls import reverse from nested_admin.tests.base import BaseNestedAdminTestCase from .models import StackedGroup, StackedSection, StackedItem @@ -24,8 +24,6 @@ def get_perm(Model, perm): class TestInlinePermissions(TestCase): def setUp(self): - if django.VERSION < (2, 1): - raise SkipTest("View permissions not available before django 2.1") super(TestInlinePermissions, self).setUp() self.group = StackedGroup.objects.create(pk=1, slug='group') @@ -161,8 +159,6 @@ class SeleniumTestInlinePermissions(BaseNestedAdminTestCase): @classmethod def setUpClass(cls): - if django.VERSION < (2, 1): - raise SkipTest("View permissions not available before django 2.1") super(SeleniumTestInlinePermissions, cls).setUpClass() cls.section_cls, cls.item_cls = cls.nested_models diff --git a/nested_admin/tests/two_deep/tests.py b/nested_admin/tests/two_deep/tests.py index 80ad1649..fadf02a2 100644 --- a/nested_admin/tests/two_deep/tests.py +++ b/nested_admin/tests/two_deep/tests.py @@ -821,8 +821,6 @@ class TestStackedInlineAdmin(InlineAdminTestCaseMixin, BaseNestedAdminTestCase): nested_models = (StackedSection, StackedItem) def test_add_item_inline_label_update(self): - if django.VERSION < (1, 9): - raise SkipTest("Test only applies to Django 1.9+") if self.has_grappelli: raise SkipTest("Test does not apply if using django-grappelli") if self.has_suit: diff --git a/nested_admin/tests/urls.py b/nested_admin/tests/urls.py index a8b4be66..18294218 100644 --- a/nested_admin/tests/urls.py +++ b/nested_admin/tests/urls.py @@ -1,6 +1,6 @@ import django from django.conf import settings -from django.conf.urls import include, url +from django.urls import include, path, re_path from django.contrib import admin # Explicitly import to register the admins for the test models @@ -10,17 +10,14 @@ urlpatterns = [ - url(r'^_nesting/', include('nested_admin.urls')), + path('_nesting/', include('nested_admin.urls')), ] -if django.VERSION < (1, 9): - urlpatterns += [url(r'^admin/', include(admin.site.urls))] -else: - urlpatterns += [url(r'^admin/', admin.site.urls)] +urlpatterns += [re_path(r'^admin/', admin.site.urls)] try: import grappelli except ImportError: pass else: - urlpatterns += [url(r"^grappelli/", include("grappelli.urls"))] + urlpatterns += [path("grappelli/", include("grappelli.urls"))] diff --git a/nested_admin/urls.py b/nested_admin/urls.py index 2d1101a3..cf01f82e 100644 --- a/nested_admin/urls.py +++ b/nested_admin/urls.py @@ -1,10 +1,10 @@ -from django.conf.urls import url +from django.urls import re_path import nested_admin.views urlpatterns = [ - url(r'^server-data\.js$', nested_admin.views.server_data_js, + re_path(r'^server-data\.js$', nested_admin.views.server_data_js, name="nesting_server_data"), ] diff --git a/nested_admin/views.py b/nested_admin/views.py index baf9b55d..21e20921 100644 --- a/nested_admin/views.py +++ b/nested_admin/views.py @@ -7,7 +7,7 @@ from django.urls import reverse, NoReverseMatch except ImportError: # Django <= 1.9 - from django.core.urlresolvers import reverse, NoReverseMatch + from django.urls import NoReverseMatch, reverse from django.http import HttpResponse, HttpResponseForbidden From b10bee645076f444c4b6039562da5ed2ac03f596 Mon Sep 17 00:00:00 2001 From: raybittuiq Date: Wed, 27 Nov 2024 22:27:07 +0530 Subject: [PATCH 2/3] removed the changes which were not required --- nested_admin/formsets.py | 2 +- nested_admin/nested.py | 2 +- nested_admin/tests/two_deep/test_permissions.py | 2 +- nested_admin/views.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nested_admin/formsets.py b/nested_admin/formsets.py index dc425e13..6ff685a4 100644 --- a/nested_admin/formsets.py +++ b/nested_admin/formsets.py @@ -12,7 +12,7 @@ from six.moves import range if six.PY2: - from django.utils.encoding import force_str as force_str + from django.utils.encoding import force_text as force_str else: from django.utils.encoding import force_str diff --git a/nested_admin/nested.py b/nested_admin/nested.py index 2eae337f..44dd283e 100644 --- a/nested_admin/nested.py +++ b/nested_admin/nested.py @@ -9,7 +9,7 @@ from django.urls import reverse except ImportError: # Django <= 1.9 - from django.urls import reverse + from django.core.urlresolvers import reverse from django.template.defaultfilters import capfirst import six from django.utils.functional import lazy diff --git a/nested_admin/tests/two_deep/test_permissions.py b/nested_admin/tests/two_deep/test_permissions.py index db71731f..a9748ba2 100644 --- a/nested_admin/tests/two_deep/test_permissions.py +++ b/nested_admin/tests/two_deep/test_permissions.py @@ -9,7 +9,7 @@ try: from django.urls import reverse except ImportError: - from django.urls import reverse + from django.core.urlresolvers import reverse from nested_admin.tests.base import BaseNestedAdminTestCase from .models import StackedGroup, StackedSection, StackedItem diff --git a/nested_admin/views.py b/nested_admin/views.py index 21e20921..baf9b55d 100644 --- a/nested_admin/views.py +++ b/nested_admin/views.py @@ -7,7 +7,7 @@ from django.urls import reverse, NoReverseMatch except ImportError: # Django <= 1.9 - from django.urls import NoReverseMatch, reverse + from django.core.urlresolvers import reverse, NoReverseMatch from django.http import HttpResponse, HttpResponseForbidden From f0eca4d9677a1ea169ab939967f32558dbefd7cd Mon Sep 17 00:00:00 2001 From: raybittuiq Date: Wed, 27 Nov 2024 22:39:56 +0530 Subject: [PATCH 3/3] fixex more issues --- nested_admin/templatetags/nested_admin.py | 2 +- nested_admin/tests/urls.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nested_admin/templatetags/nested_admin.py b/nested_admin/templatetags/nested_admin.py index a8eb8316..2a03c123 100644 --- a/nested_admin/templatetags/nested_admin.py +++ b/nested_admin/templatetags/nested_admin.py @@ -24,7 +24,7 @@ def static(path): global _static if _static is None: if apps.is_installed('django-contrib.staticfiles'): - from django.templatetags.static import static as _static + from django.contrib.staticfiles.templatetags.staticfiles import static as _static else: from django.templatetags.static import static as _static if django.VERSION >= (1, 9) and path == 'admin/img/icon-unknown.gif': diff --git a/nested_admin/tests/urls.py b/nested_admin/tests/urls.py index 18294218..139047c3 100644 --- a/nested_admin/tests/urls.py +++ b/nested_admin/tests/urls.py @@ -1,6 +1,6 @@ import django from django.conf import settings -from django.urls import include, path, re_path +from django.urls import include, re_path from django.contrib import admin # Explicitly import to register the admins for the test models @@ -10,7 +10,7 @@ urlpatterns = [ - path('_nesting/', include('nested_admin.urls')), + re_path(r'^_nesting/', include('nested_admin.urls')), ] urlpatterns += [re_path(r'^admin/', admin.site.urls)] @@ -20,4 +20,4 @@ except ImportError: pass else: - urlpatterns += [path("grappelli/", include("grappelli.urls"))] + urlpatterns += [re_path(r"^grappelli/", include("grappelli.urls"))]