Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ran django-upgrades #2

Open
wants to merge 3 commits into
base: create-base-branch-for-dj-4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions nested_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions nested_admin/formsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions nested_admin/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nested_admin/polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
],
})
Expand Down
5 changes: 1 addition & 4 deletions nested_admin/templatetags/nested_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions nested_admin/tests/admin_widgets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions nested_admin/tests/nested_polymorphic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nested_admin/tests/one_deep/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 14 additions & 30 deletions nested_admin/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions nested_admin/tests/two_deep/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions nested_admin/tests/two_deep/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions nested_admin/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django
from django.conf import settings
from django.conf.urls import include, url
from django.urls import include, re_path
from django.contrib import admin

# Explicitly import to register the admins for the test models
Expand All @@ -10,17 +10,14 @@


urlpatterns = [
url(r'^_nesting/', include('nested_admin.urls')),
re_path(r'^_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 += [re_path(r"^grappelli/", include("grappelli.urls"))]
4 changes: 2 additions & 2 deletions nested_admin/urls.py
Original file line number Diff line number Diff line change
@@ -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"),
]