Browse Source

Fix urlresolvers deprecation in Django 1.11 (#210)

Alin Panaitiu 8 years ago
parent
commit
4028604ad2

+ 5 - 1
jet/dashboard/dashboard.py

@@ -1,5 +1,9 @@
 from importlib import import_module
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.template.loader import render_to_string
 from jet.dashboard import modules
 from jet.dashboard.models import UserDashboardModule

+ 5 - 1
jet/dashboard/dashboard_modules/google_analytics.py

@@ -2,7 +2,11 @@
 import datetime
 import json
 from django import forms
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.forms import Widget
 from django.utils import formats
 from django.utils.html import format_html

+ 5 - 1
jet/dashboard/dashboard_modules/google_analytics_views.py

@@ -1,4 +1,8 @@
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.conf.urls import url
 from django.contrib import messages
 from django.shortcuts import redirect

+ 5 - 1
jet/dashboard/dashboard_modules/yandex_metrika.py

@@ -2,7 +2,11 @@
 import datetime
 import json
 from django import forms
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.forms import Widget
 from django.utils import formats
 from django.utils.html import format_html

+ 5 - 1
jet/dashboard/dashboard_modules/yandex_metrika_views.py

@@ -1,6 +1,10 @@
 from django.conf.urls import url
 from django.contrib import messages
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.http import HttpResponse
 from django.shortcuts import redirect
 from jet.dashboard.dashboard_modules.yandex_metrika import YandexMetrikaClient

+ 5 - 1
jet/dashboard/views.py

@@ -1,6 +1,10 @@
 from django.contrib import messages
 from django.core.exceptions import ValidationError
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.forms.formsets import formset_factory
 from django.http import HttpResponseRedirect
 from django.views.decorators.http import require_POST, require_GET

+ 4 - 1
jet/filters.py

@@ -1,7 +1,10 @@
 from django.contrib.admin import RelatedFieldListFilter
 from django.utils.encoding import smart_text
 from django.utils.html import format_html
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
 
 try:
     from django.contrib.admin.utils import get_model_from_relation

+ 5 - 1
jet/templatetags/jet_tags.py

@@ -2,7 +2,11 @@ from __future__ import unicode_literals
 import json
 import os
 from django import template
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.forms import CheckboxInput, ModelChoiceField, Select, ModelMultipleChoiceField, SelectMultiple
 from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
 from django.utils.formats import get_format

+ 5 - 1
jet/tests/test_dashboard.py

@@ -1,5 +1,9 @@
 from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.test import TestCase, Client
 from jet.dashboard.dashboard import Dashboard
 from jet.dashboard.modules import LinkList, RecentActions

+ 5 - 1
jet/tests/test_tags.py

@@ -1,5 +1,9 @@
 from django import forms
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.test import TestCase
 from jet.templatetags.jet_tags import jet_select2_lookups, jet_next_object, jet_previous_object
 from jet.tests.models import TestModel, SearchableTestModel

+ 5 - 1
jet/tests/test_views.py

@@ -1,6 +1,10 @@
 import json
 from django.contrib.auth.models import User
-from django.core.urlresolvers import reverse
+try:
+    from django.core.urlresolvers import reverse
+except ImportError: # Django 1.11
+    from django.urls import reverse
+
 from django.test import TestCase, Client
 from jet.dashboard.modules import LinkList
 from jet.models import Bookmark

+ 6 - 3
jet/utils.py

@@ -14,7 +14,11 @@ except ImportError:
         pass
 from django.core.serializers.json import DjangoJSONEncoder
 from django.http import HttpResponse
-from django.core.urlresolvers import reverse, resolve, NoReverseMatch
+try:
+    from django.core.urlresolvers import reverse, resolve, NoReverseMatch
+except ImportError: # Django 1.11
+    from django.urls import reverse, resolve, NoReverseMatch
+
 from django.contrib.admin import AdminSite
 from django.utils.encoding import smart_text
 from django.utils.text import capfirst
@@ -22,7 +26,6 @@ from django.contrib import messages
 from django.utils.encoding import force_text
 from django.utils.functional import Promise
 from django.contrib.admin.options import IncorrectLookupParameters
-from django.core import urlresolvers
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 from django.utils.text import slugify
@@ -178,7 +181,7 @@ def get_model_queryset(admin_site, model, request, preserved_filters=None):
     model_admin = admin_site._registry.get(model)
 
     try:
-        changelist_url = urlresolvers.reverse('%s:%s_%s_changelist' % (
+        changelist_url = reverse('%s:%s_%s_changelist' % (
             admin_site.name,
             model._meta.app_label,
             model._meta.model_name