From a7512c8745381a273c886857c7b906390366a0df Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 12 Mar 2020 10:31:54 +0500 Subject: [PATCH] BOM-1399 Fixing urls import issue. --- setup.py | 2 +- testproject/testproject/settings.py | 2 +- wiki/conf/settings.py | 2 +- wiki/decorators.py | 2 +- wiki/editors/__init__.py | 2 +- wiki/models/__init__.py | 31 +++++++++---------- wiki/models/urlpath.py | 2 +- .../attachments/markdown_extensions.py | 2 +- wiki/plugins/images/views.py | 2 +- wiki/plugins/links/wiki_plugin.py | 2 +- wiki/plugins/notifications/models.py | 2 +- wiki/views/accounts.py | 2 +- wiki/views/article.py | 2 +- 13 files changed, 26 insertions(+), 29 deletions(-) diff --git a/setup.py b/setup.py index 6069ad7bc..a8380241d 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ def build_media_pattern(base_folder, file_extension): setup( name = "django-wiki", - version="0.0.25", + version="0.0.26", author="Benjamin Bach", author_email="benjamin@overtag.dk", description=("A wiki system written for the Django framework."), diff --git a/testproject/testproject/settings.py b/testproject/testproject/settings.py index 4b428be32..b184c5161 100644 --- a/testproject/testproject/settings.py +++ b/testproject/testproject/settings.py @@ -11,7 +11,7 @@ # ('Your Name', 'your_email@example.com'), ) -#from django.core.urlresolvers import reverse_lazy +#from django.urls import reverse_lazy #LOGIN_REDIRECT_URL = reverse_lazy('wiki:get', kwargs={'path': ''}) # This forces the wiki login view to redirect to the referer... diff --git a/wiki/conf/settings.py b/wiki/conf/settings.py index 46f0b3cfc..178727b1f 100644 --- a/wiki/conf/settings.py +++ b/wiki/conf/settings.py @@ -2,7 +2,7 @@ from __future__ import absolute_import from django.conf import settings as django_settings -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy # Should urls be case sensitive? URL_CASE_SENSITIVE = getattr(django_settings, 'WIKI_URL_CASE_SENSITIVE', False) diff --git a/wiki/decorators.py b/wiki/decorators.py index b584be473..e90c4634d 100644 --- a/wiki/decorators.py +++ b/wiki/decorators.py @@ -4,12 +4,12 @@ import json from django.conf import settings as django_settings -from django.core.urlresolvers import reverse from django.http import (HttpResponse, HttpResponseForbidden, HttpResponseNotFound) from django.shortcuts import get_object_or_404, redirect from django.template.context import RequestContext from django.template.loader import render_to_string +from django.urls import reverse from six.moves import filter from wiki.core.exceptions import NoRootURL diff --git a/wiki/editors/__init__.py b/wiki/editors/__init__.py index d95eb0dbd..d1a3d88eb 100644 --- a/wiki/editors/__init__.py +++ b/wiki/editors/__init__.py @@ -1,6 +1,6 @@ from __future__ import absolute_import -from django.core.urlresolvers import get_callable +from django.urls import get_callable from wiki.conf import settings diff --git a/wiki/models/__init__.py b/wiki/models/__init__.py index f3e37ad8f..b18f349d5 100644 --- a/wiki/models/__init__.py +++ b/wiki/models/__init__.py @@ -60,16 +60,16 @@ load_wiki_plugins() +from django import shortcuts, urls -from django.core import urlresolvers +original_django_reverse = urls.reverse -original_django_reverse = urlresolvers.reverse def reverse(*args, **kwargs): """Now this is a crazy and silly hack, but it is basically here to enforce that an empty path always takes precedence over an article_id such that the root article doesn't get resolved to /ID/ but /. - + Another crazy hack that this supports is transforming every wiki url by a function. If _transform_url is set on this function, it will return the result of calling reverse._transform_url(reversed_url) @@ -83,31 +83,28 @@ def reverse(*args, **kwargs): url_kwargs.pop('article_id', None) url_kwargs['path'] = path kwargs['kwargs'] = url_kwargs - + url = original_django_reverse(*args, **kwargs) if hasattr(reverse, '_transform_url'): url = reverse._transform_url(url) else: url = original_django_reverse(*args, **kwargs) - + return url - + # Now we redefine reverse method reverse_lazy = lazy(reverse, text_type) -urlresolvers.reverse = reverse -urlresolvers.reverse_lazy = reverse_lazy +urls.reverse = reverse +urls.reverse_lazy = reverse_lazy # Patch up other locations of the reverse function +shortcuts.reverse = reverse 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 + # For Django 1.11 + from django.core import urlresolvers + + urlresolvers.reverse = reverse + urlresolvers.reverse_lazy = reverse_lazy except ImportError: pass diff --git a/wiki/models/urlpath.py b/wiki/models/urlpath.py index 10ea34bb7..a9f65e6e1 100644 --- a/wiki/models/urlpath.py +++ b/wiki/models/urlpath.py @@ -8,9 +8,9 @@ from django.contrib.sites.models import Site from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse from django.db import models, transaction from django.db.models.signals import post_save, pre_delete +from django.urls import reverse from django.utils.translation import ugettext from django.utils.translation import ugettext_lazy as _ from mptt.fields import TreeForeignKey diff --git a/wiki/plugins/attachments/markdown_extensions.py b/wiki/plugins/attachments/markdown_extensions.py index b6004e805..3ccabeaf3 100644 --- a/wiki/plugins/attachments/markdown_extensions.py +++ b/wiki/plugins/attachments/markdown_extensions.py @@ -3,7 +3,7 @@ import re import markdown -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.translation import ugettext as _ from wiki.plugins.attachments import models diff --git a/wiki/plugins/images/views.py b/wiki/plugins/images/views.py index ca0f47e9b..784994a3b 100644 --- a/wiki/plugins/images/views.py +++ b/wiki/plugins/images/views.py @@ -1,6 +1,6 @@ from __future__ import absolute_import 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 ugettext as _ diff --git a/wiki/plugins/links/wiki_plugin.py b/wiki/plugins/links/wiki_plugin.py index f92ea1ec8..3b72db0d2 100644 --- a/wiki/plugins/links/wiki_plugin.py +++ b/wiki/plugins/links/wiki_plugin.py @@ -9,7 +9,7 @@ from wiki.plugins.links import views from wiki.plugins.links.mdx.urlize import makeExtension from wiki.plugins.links.mdx.djangowikilinks import WikiPathExtension -from django.core.urlresolvers import reverse_lazy +from django.urls import reverse_lazy class LinkPlugin(BasePlugin): diff --git a/wiki/plugins/notifications/models.py b/wiki/plugins/notifications/models.py index 215a9e240..a9bdca2af 100644 --- a/wiki/plugins/notifications/models.py +++ b/wiki/plugins/notifications/models.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from django.core.urlresolvers import reverse +from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.db.models import signals diff --git a/wiki/views/accounts.py b/wiki/views/accounts.py index ce9e4f051..126e04114 100644 --- a/wiki/views/accounts.py +++ b/wiki/views/accounts.py @@ -10,8 +10,8 @@ from django.contrib.auth import logout as auth_logout from django.contrib.auth.forms import AuthenticationForm, UserCreationForm from django.contrib.auth.models import User -from django.core.urlresolvers import reverse from django.shortcuts import redirect +from django.urls import reverse from django.utils.translation import ugettext as _ from django.views.generic.base import View from django.views.generic.edit import CreateView, FormView diff --git a/wiki/views/article.py b/wiki/views/article.py index 4512372c9..d7115935c 100644 --- a/wiki/views/article.py +++ b/wiki/views/article.py @@ -5,11 +5,11 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required -from django.core.urlresolvers import reverse from django.db import transaction from django.db.models import Q from django.shortcuts import get_object_or_404, redirect, render_to_response from django.template.context import RequestContext +from django.urls import reverse from django.utils.decorators import method_decorator from django.utils.translation import ugettext as _ from django.views.generic.base import TemplateView, View