From 1c158253deadcaaa8d9c710fc057ef2b11e22a03 Mon Sep 17 00:00:00 2001 From: Raffaele Salmaso Date: Sun, 18 Feb 2018 22:06:34 +0100 Subject: [PATCH] Update import from django.urls instead of django.core.urlresolvers --- src/wiki/conf/settings.py | 2 +- src/wiki/decorators.py | 2 +- src/wiki/editors/__init__.py | 2 +- src/wiki/forms.py | 2 +- src/wiki/models/__init__.py | 28 +++++++------------ src/wiki/models/article.py | 2 +- src/wiki/models/urlpath.py | 2 +- .../attachments/markdown_extensions.py | 2 +- src/wiki/plugins/images/views.py | 2 +- src/wiki/plugins/links/wiki_plugin.py | 2 +- src/wiki/plugins/macros/mdx/wikilinks.py | 2 +- src/wiki/plugins/notifications/models.py | 2 +- src/wiki/views/accounts.py | 2 +- src/wiki/views/article.py | 2 +- testproject/testproject/settings/base.py | 2 +- tests/base.py | 2 +- tests/plugins/attachments/test_views.py | 2 +- .../globalhistory/test_globalhistory.py | 2 +- tests/plugins/images/test_views.py | 2 +- tests/plugins/links/test_links.py | 2 +- tests/settings.py | 2 +- 21 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/wiki/conf/settings.py b/src/wiki/conf/settings.py index 0f35e234..255da842 100644 --- a/src/wiki/conf/settings.py +++ b/src/wiki/conf/settings.py @@ -4,7 +4,7 @@ from django.apps import apps from django.conf import settings as django_settings from django.contrib.messages import constants as messages from django.core.files.storage import default_storage -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ #: Should urls be case sensitive? diff --git a/src/wiki/decorators.py b/src/wiki/decorators.py index 4d25aebc..329b2c6c 100644 --- a/src/wiki/decorators.py +++ b/src/wiki/decorators.py @@ -1,6 +1,6 @@ from functools import wraps -from django.core.urlresolvers import reverse +from django.urls import reverse from django.http import (HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect) from django.shortcuts import get_object_or_404, redirect diff --git a/src/wiki/editors/__init__.py b/src/wiki/editors/__init__.py index 42480ef2..2fb0aa58 100644 --- a/src/wiki/editors/__init__.py +++ b/src/wiki/editors/__init__.py @@ -1,5 +1,5 @@ from wiki.conf import settings -from django.core.urlresolvers import get_callable +from django.urls import get_callable _EditorClass = None _editor = None diff --git a/src/wiki/forms.py b/src/wiki/forms.py index 72447a5f..b1de8485 100644 --- a/src/wiki/forms.py +++ b/src/wiki/forms.py @@ -8,7 +8,7 @@ from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.forms import UserCreationForm from django.core import validators -from django.core.urlresolvers import Resolver404, resolve +from django.urls import Resolver404, resolve from django.core.validators import RegexValidator from django.forms.utils import flatatt from django.forms.widgets import HiddenInput diff --git a/src/wiki/models/__init__.py b/src/wiki/models/__init__.py index 8ccc7b0f..a9357924 100644 --- a/src/wiki/models/__init__.py +++ b/src/wiki/models/__init__.py @@ -1,6 +1,9 @@ from django.apps import apps from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured +from django.urls import base +from django import urls +from django import shortcuts # TODO: Don't use wildcards from .article import * # noqa @@ -60,9 +63,7 @@ if apps.is_installed('django_notify'): 'django-wiki: You need to change from django_notify to django_nyt in INSTALLED_APPS and your urlconfig.') -from django.core import urlresolvers # noqa - -original_django_reverse = urlresolvers.reverse +original_django_reverse = urls.reverse def reverse(*args, **kwargs): @@ -93,21 +94,12 @@ def reverse(*args, **kwargs): return url -# Now we redefine reverse method reverse_lazy = lazy(reverse, str) -urlresolvers.reverse = reverse -urlresolvers.reverse_lazy = reverse_lazy + # Patch up other locations of the reverse function -try: - from django.urls import base - from django import urls - from django import shortcuts - base.reverse = reverse - base.reverse_lazy = reverse_lazy - urls.reverse = reverse - urls.reverse_lazy = reverse_lazy - shortcuts.reverse = reverse - urls.reverse_lazy = reverse_lazy -except ImportError: - pass +base.reverse = reverse +base.reverse_lazy = reverse_lazy +urls.reverse = reverse +urls.reverse_lazy = reverse_lazy +shortcuts.reverse = reverse diff --git a/src/wiki/models/article.py b/src/wiki/models/article.py index 8e84f7a7..00c3bb92 100644 --- a/src/wiki/models/article.py +++ b/src/wiki/models/article.py @@ -1,7 +1,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.core.cache import cache -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from django.db.models.fields import GenericIPAddressField as IPAddressField from django.db.models.signals import post_save, pre_delete, pre_save diff --git a/src/wiki/models/urlpath.py b/src/wiki/models/urlpath.py index ba568814..809b336a 100644 --- a/src/wiki/models/urlpath.py +++ b/src/wiki/models/urlpath.py @@ -5,7 +5,7 @@ from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models, transaction from django.db.models.signals import post_save, pre_delete # Django 1.6 transaction API, required for 1.8+ diff --git a/src/wiki/plugins/attachments/markdown_extensions.py b/src/wiki/plugins/attachments/markdown_extensions.py index 55839b77..848f063c 100644 --- a/src/wiki/plugins/attachments/markdown_extensions.py +++ b/src/wiki/plugins/attachments/markdown_extensions.py @@ -2,7 +2,7 @@ import re import markdown from django.contrib.auth.models import AnonymousUser -from django.core.urlresolvers import reverse +from django.urls import reverse from django.template.loader import render_to_string from wiki.core.permissions import can_read from wiki.plugins.attachments import models diff --git a/src/wiki/plugins/images/views.py b/src/wiki/plugins/images/views.py index 8fe3ac6d..678c9da4 100644 --- a/src/wiki/plugins/images/views.py +++ b/src/wiki/plugins/images/views.py @@ -1,7 +1,7 @@ import logging from django.contrib import messages -from django.core.urlresolvers import reverse +from django.urls import reverse from django.shortcuts import get_object_or_404, redirect from django.utils.decorators import method_decorator from django.utils.translation import gettext as _ diff --git a/src/wiki/plugins/links/wiki_plugin.py b/src/wiki/plugins/links/wiki_plugin.py index 00af4e3a..005a3e56 100644 --- a/src/wiki/plugins/links/wiki_plugin.py +++ b/src/wiki/plugins/links/wiki_plugin.py @@ -1,5 +1,5 @@ from django.conf.urls import url -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.utils.translation import gettext as _ from wiki.core.plugins import registry from wiki.core.plugins.base import BasePlugin diff --git a/src/wiki/plugins/macros/mdx/wikilinks.py b/src/wiki/plugins/macros/mdx/wikilinks.py index 4b8c85b3..31e375b6 100644 --- a/src/wiki/plugins/macros/mdx/wikilinks.py +++ b/src/wiki/plugins/macros/mdx/wikilinks.py @@ -5,7 +5,7 @@ Extend the shipped Markdown extension 'wikilinks' import re import markdown -from django.core.urlresolvers import reverse +from django.urls import reverse from markdown.extensions import wikilinks diff --git a/src/wiki/plugins/notifications/models.py b/src/wiki/plugins/notifications/models.py index b1f663f3..47e9a0d3 100644 --- a/src/wiki/plugins/notifications/models.py +++ b/src/wiki/plugins/notifications/models.py @@ -1,6 +1,6 @@ -from django.core.urlresolvers import reverse from django.db import models from django.db.models import signals +from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django_nyt.models import Subscription from django_nyt.utils import notify diff --git a/src/wiki/views/accounts.py b/src/wiki/views/accounts.py index ea41d1eb..165b7bc8 100644 --- a/src/wiki/views/accounts.py +++ b/src/wiki/views/accounts.py @@ -14,7 +14,7 @@ from django.contrib import messages from django.contrib.auth import get_user_model, login as auth_login from django.contrib.auth import logout as auth_logout from django.contrib.auth.forms import AuthenticationForm -from django.core.urlresolvers import reverse +from django.urls import reverse from django.shortcuts import get_object_or_404, redirect, render from django.utils.translation import gettext as _ from django.views.generic.base import View diff --git a/src/wiki/views/article.py b/src/wiki/views/article.py index fb3e8e9d..172cf482 100644 --- a/src/wiki/views/article.py +++ b/src/wiki/views/article.py @@ -3,7 +3,7 @@ import logging from django.contrib import messages from django.contrib.auth.decorators import login_required -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import transaction from django.db.models import Q from django.http import Http404 diff --git a/testproject/testproject/settings/base.py b/testproject/testproject/settings/base.py index 2acacfb1..1f54d1e9 100644 --- a/testproject/testproject/settings/base.py +++ b/testproject/testproject/settings/base.py @@ -10,7 +10,7 @@ https://docs.djangoproject.com/en/1.9/ref/settings/ import os -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/tests/base.py b/tests/base.py index 2e95b03b..596905a4 100644 --- a/tests/base.py +++ b/tests/base.py @@ -3,7 +3,7 @@ import unittest import django_functest from django.contrib.staticfiles.testing import StaticLiveServerTestCase -from django.core.urlresolvers import reverse +from django.urls import reverse from django.template import Context, Template from django.test import TestCase, override_settings diff --git a/tests/plugins/attachments/test_views.py b/tests/plugins/attachments/test_views.py index 7b355e64..ae5295f7 100644 --- a/tests/plugins/attachments/test_views.py +++ b/tests/plugins/attachments/test_views.py @@ -1,7 +1,7 @@ from io import BytesIO from django.core.files.uploadedfile import InMemoryUploadedFile -from django.core.urlresolvers import reverse +from django.urls import reverse from wiki.models import URLPath from ...base import RequireRootArticleMixin, ArticleWebTestUtils, DjangoClientTestBase diff --git a/tests/plugins/globalhistory/test_globalhistory.py b/tests/plugins/globalhistory/test_globalhistory.py index 4dcd3d6b..b3ef8eff 100644 --- a/tests/plugins/globalhistory/test_globalhistory.py +++ b/tests/plugins/globalhistory/test_globalhistory.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import reverse +from django.urls import reverse from wiki.models import URLPath from ...base import (ArticleWebTestUtils, DjangoClientTestBase, diff --git a/tests/plugins/images/test_views.py b/tests/plugins/images/test_views.py index 1da84392..67744ede 100644 --- a/tests/plugins/images/test_views.py +++ b/tests/plugins/images/test_views.py @@ -2,7 +2,7 @@ import base64 from io import BytesIO from django.core.files.uploadedfile import InMemoryUploadedFile -from django.core.urlresolvers import reverse +from django.urls import reverse from wiki.core.plugins import registry as plugin_registry from wiki.models import URLPath from wiki.plugins.images import models diff --git a/tests/plugins/links/test_links.py b/tests/plugins/links/test_links.py index 17e53be2..26fa78ed 100644 --- a/tests/plugins/links/test_links.py +++ b/tests/plugins/links/test_links.py @@ -1,5 +1,5 @@ import markdown -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy from django.test import TestCase from wiki.models import URLPath from wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension diff --git a/tests/settings.py b/tests/settings.py index f573ae22..8a28cb97 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,6 +1,6 @@ import os -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy TESTS_DATA_ROOT = os.path.dirname(__file__) -- 2.45.2