[PATCH 06/19] compat: Handle moved 'reverse' function
Stephen Finucane
stephen at that.guru
Thu May 11 05:45:15 AEST 2017
This raises a warning in Django 1.10 and will cause an error in 2.0.
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/compat.py | 13 +++++++++++++
patchwork/templatetags/listurl.py | 3 ++-
patchwork/templatetags/person.py | 2 +-
patchwork/tests/test_about.py | 3 ++-
patchwork/tests/test_bundles.py | 2 +-
patchwork/tests/test_completion.py | 2 +-
patchwork/tests/test_confirm.py | 2 +-
patchwork/tests/test_detail.py | 2 +-
patchwork/tests/test_encodings.py | 2 +-
patchwork/tests/test_filters.py | 2 +-
patchwork/tests/test_list.py | 2 +-
patchwork/tests/test_mail_settings.py | 2 +-
patchwork/tests/test_mboxviews.py | 2 +-
patchwork/tests/test_paginator.py | 2 +-
patchwork/tests/test_projects.py | 2 +-
patchwork/tests/test_registration.py | 2 +-
patchwork/tests/test_rest_api.py | 2 +-
patchwork/tests/test_updates.py | 2 +-
patchwork/tests/test_user.py | 2 +-
patchwork/tests/test_user_browser.py | 3 +--
patchwork/tests/test_xmlrpc.py | 2 +-
patchwork/views/about.py | 3 ++-
patchwork/views/bundle.py | 16 +++++++---------
patchwork/views/comment.py | 5 ++---
patchwork/views/cover.py | 6 ++----
patchwork/views/mail.py | 2 +-
patchwork/views/patch.py | 6 ++----
patchwork/views/project.py | 6 +++---
patchwork/views/user.py | 6 +++---
patchwork/views/xmlrpc.py | 2 +-
30 files changed, 58 insertions(+), 50 deletions(-)
diff --git a/patchwork/compat.py b/patchwork/compat.py
index af7d684..cd4da4c 100644
--- a/patchwork/compat.py
+++ b/patchwork/compat.py
@@ -76,3 +76,16 @@ if settings.ENABLE_REST_API:
LOOKUP_FIELD = 'lookup_expr'
else:
LOOKUP_FIELD = 'lookup_type'
+
+
+# reverse
+#
+# The reverse function has been moved to django.urls in Django 1.10 and
+# backwards compatible imports will be removed in Django 2.0
+
+if django.VERSION >= (1, 10):
+ from django.urls import NoReverseMatch # noqa
+ from django.urls import reverse # noqa
+else:
+ from django.core.urlresolvers import NoReverseMatch # noqa
+ from django.core.urlresolvers import reverse # noqa
diff --git a/patchwork/templatetags/listurl.py b/patchwork/templatetags/listurl.py
index 9d3b685..6b9106e 100644
--- a/patchwork/templatetags/listurl.py
+++ b/patchwork/templatetags/listurl.py
@@ -20,11 +20,12 @@
from __future__ import absolute_import
from django.conf import settings
-from django.core.urlresolvers import reverse, NoReverseMatch
from django import template
from django.utils.encoding import smart_str
from django.utils.html import escape
+from patchwork.compat import reverse
+from patchwork.compat import NoReverseMatch
from patchwork.filters import filterclasses
diff --git a/patchwork/templatetags/person.py b/patchwork/templatetags/person.py
index adbabb0..a6f23e9 100644
--- a/patchwork/templatetags/person.py
+++ b/patchwork/templatetags/person.py
@@ -19,11 +19,11 @@
from __future__ import absolute_import
-from django.core.urlresolvers import reverse
from django import template
from django.utils.html import escape
from django.utils.safestring import mark_safe
+from patchwork.compat import reverse
from patchwork.filters import SubmitterFilter
diff --git a/patchwork/tests/test_about.py b/patchwork/tests/test_about.py
index 24246ed..f405968 100644
--- a/patchwork/tests/test_about.py
+++ b/patchwork/tests/test_about.py
@@ -17,9 +17,10 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
+
class AboutViewTest(TestCase):
diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
index 7f98d36..0dc9165 100644
--- a/patchwork/tests/test_bundles.py
+++ b/patchwork/tests/test_bundles.py
@@ -23,13 +23,13 @@ import datetime
import unittest
from django.conf import settings
-from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.http import urlencode
from django.utils import six
from django.utils.six.moves import range
from django.utils.six.moves import zip
+from patchwork.compat import reverse
from patchwork.models import Bundle
from patchwork.models import BundlePatch
from patchwork.tests.utils import create_bundle
diff --git a/patchwork/tests/test_completion.py b/patchwork/tests/test_completion.py
index a07999a..8297e57 100644
--- a/patchwork/tests/test_completion.py
+++ b/patchwork/tests/test_completion.py
@@ -21,10 +21,10 @@ from __future__ import absolute_import
import json
-from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.six.moves import range
+from patchwork.compat import reverse
from patchwork.tests.utils import create_person
diff --git a/patchwork/tests/test_confirm.py b/patchwork/tests/test_confirm.py
index ff3e383..ed26431 100644
--- a/patchwork/tests/test_confirm.py
+++ b/patchwork/tests/test_confirm.py
@@ -17,9 +17,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.models import EmailConfirmation
from patchwork.tests.utils import create_user
diff --git a/patchwork/tests/test_detail.py b/patchwork/tests/test_detail.py
index ef93bbf..5d8534e 100644
--- a/patchwork/tests/test_detail.py
+++ b/patchwork/tests/test_detail.py
@@ -19,9 +19,9 @@
from __future__ import absolute_import
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests.utils import create_comment
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_patch
diff --git a/patchwork/tests/test_encodings.py b/patchwork/tests/test_encodings.py
index fd49578..fe094d5 100644
--- a/patchwork/tests/test_encodings.py
+++ b/patchwork/tests/test_encodings.py
@@ -16,9 +16,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests.utils import create_person
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import read_patch
diff --git a/patchwork/tests/test_filters.py b/patchwork/tests/test_filters.py
index 0689b0c..23cf0ff 100644
--- a/patchwork/tests/test_filters.py
+++ b/patchwork/tests/test_filters.py
@@ -17,9 +17,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests.utils import create_project
diff --git a/patchwork/tests/test_list.py b/patchwork/tests/test_list.py
index 4a54001..11b9da9 100644
--- a/patchwork/tests/test_list.py
+++ b/patchwork/tests/test_list.py
@@ -22,10 +22,10 @@ from __future__ import absolute_import
from datetime import datetime as dt
import re
-from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.six.moves import zip
+from patchwork.compat import reverse
from patchwork.models import Patch
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_person
diff --git a/patchwork/tests/test_mail_settings.py b/patchwork/tests/test_mail_settings.py
index b96b0b5..1eb4975 100644
--- a/patchwork/tests/test_mail_settings.py
+++ b/patchwork/tests/test_mail_settings.py
@@ -20,9 +20,9 @@
import re
from django.core import mail
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.models import EmailOptout
from patchwork.models import EmailConfirmation
from patchwork.tests.utils import create_person
diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py
index 31c3b85..0dc4abb 100644
--- a/patchwork/tests/test_mboxviews.py
+++ b/patchwork/tests/test_mboxviews.py
@@ -24,9 +24,9 @@ import dateutil.parser
import dateutil.tz
import email
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests.utils import create_comment
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_project
diff --git a/patchwork/tests/test_paginator.py b/patchwork/tests/test_paginator.py
index 8597f6a..2291eb0 100644
--- a/patchwork/tests/test_paginator.py
+++ b/patchwork/tests/test_paginator.py
@@ -17,9 +17,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests.utils import create_patches
from patchwork.tests.utils import create_project
from patchwork.tests.utils import create_user
diff --git a/patchwork/tests/test_projects.py b/patchwork/tests/test_projects.py
index 8390419..804bdda 100644
--- a/patchwork/tests/test_projects.py
+++ b/patchwork/tests/test_projects.py
@@ -17,9 +17,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.tests import utils
diff --git a/patchwork/tests/test_registration.py b/patchwork/tests/test_registration.py
index 3f210d3..28581eb 100644
--- a/patchwork/tests/test_registration.py
+++ b/patchwork/tests/test_registration.py
@@ -19,10 +19,10 @@
from django.contrib.auth.models import User
from django.core import mail
-from django.core.urlresolvers import reverse
from django.test.client import Client
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.models import EmailConfirmation, Person
from patchwork.tests.utils import create_user
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index c63f672..2b064a2 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -21,8 +21,8 @@ from email.utils import make_msgid
import unittest
from django.conf import settings
-from django.core.urlresolvers import reverse
+from patchwork.compat import reverse
from patchwork.models import Check
from patchwork.models import Patch
from patchwork.models import Project
diff --git a/patchwork/tests/test_updates.py b/patchwork/tests/test_updates.py
index ec5816c..80367f4 100644
--- a/patchwork/tests/test_updates.py
+++ b/patchwork/tests/test_updates.py
@@ -17,9 +17,9 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.models import Patch
from patchwork.models import State
from patchwork.tests.utils import create_patches
diff --git a/patchwork/tests/test_user.py b/patchwork/tests/test_user.py
index b2cc825..6dd41e1 100644
--- a/patchwork/tests/test_user.py
+++ b/patchwork/tests/test_user.py
@@ -19,9 +19,9 @@
from django.contrib.auth.models import User
from django.core import mail
-from django.core.urlresolvers import reverse
from django.test import TestCase
+from patchwork.compat import reverse
from patchwork.models import EmailConfirmation
from patchwork.models import Person
from patchwork.models import UserProfile
diff --git a/patchwork/tests/test_user_browser.py b/patchwork/tests/test_user_browser.py
index d09b341..ad4143f 100644
--- a/patchwork/tests/test_user_browser.py
+++ b/patchwork/tests/test_user_browser.py
@@ -17,8 +17,7 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core.urlresolvers import reverse
-
+from patchwork.compat import reverse
from patchwork.tests.browser import SeleniumTestCase
from patchwork.tests.utils import create_user
diff --git a/patchwork/tests/test_xmlrpc.py b/patchwork/tests/test_xmlrpc.py
index ddaded8..8edc07a 100644
--- a/patchwork/tests/test_xmlrpc.py
+++ b/patchwork/tests/test_xmlrpc.py
@@ -20,10 +20,10 @@
import unittest
from django.conf import settings
-from django.core.urlresolvers import reverse
from django.test import LiveServerTestCase
from django.utils.six.moves import xmlrpc_client
+from patchwork.compat import reverse
from patchwork.tests import utils
diff --git a/patchwork/views/about.py b/patchwork/views/about.py
index 6d8579d..24a0845 100644
--- a/patchwork/views/about.py
+++ b/patchwork/views/about.py
@@ -19,10 +19,11 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.conf import settings
-from django.core.urlresolvers import reverse
from django.http import HttpResponsePermanentRedirect
from django.shortcuts import render
+from patchwork.compat import reverse
+
def about(request):
context = {
diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py
index 89acb34..dc9b74b 100644
--- a/patchwork/views/bundle.py
+++ b/patchwork/views/bundle.py
@@ -19,13 +19,13 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
-from django.core import urlresolvers
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.http import HttpResponseNotFound
from django.shortcuts import get_object_or_404
from django.shortcuts import render
+from patchwork.compat import reverse
from patchwork.filters import DelegateFilter
from patchwork.forms import BundleForm
from patchwork.forms import DeleteBundleForm
@@ -89,9 +89,7 @@ def bundle_detail(request, username, bundlename):
action = request.POST.get('action', '').lower()
if action == 'delete':
bundle.delete()
- return HttpResponseRedirect(
- urlresolvers.reverse('user-profile')
- )
+ return HttpResponseRedirect(reverse('user-profile'))
elif action == 'update':
form = BundleForm(request.POST, instance=bundle)
if form.is_valid():
@@ -163,8 +161,8 @@ def bundle_detail_redir(request, bundle_id):
@login_required
def bundle_mbox_redir(request, bundle_id):
bundle = get_object_or_404(Bundle, id=bundle_id, owner=request.user)
- return HttpResponseRedirect(urlresolvers.reverse(
- 'bundle-mbox', kwargs={
- 'username': request.user.username,
- 'bundlename': bundle.name,
- }))
+ return HttpResponseRedirect(
+ reverse('bundle-mbox', kwargs={
+ 'username': request.user.username,
+ 'bundlename': bundle.name,
+ }))
diff --git a/patchwork/views/comment.py b/patchwork/views/comment.py
index e4f4f89..987f76c 100644
--- a/patchwork/views/comment.py
+++ b/patchwork/views/comment.py
@@ -17,10 +17,10 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core import urlresolvers
from django import http
from django import shortcuts
+from patchwork.compat import reverse
from patchwork import models
@@ -35,5 +35,4 @@ def comment(request, comment_id):
key = 'cover_id'
return http.HttpResponseRedirect('%s#%s' % (
- urlresolvers.reverse(url, kwargs={key: submission.id}),
- comment_id))
+ reverse(url, kwargs={key: submission.id}), comment_id))
diff --git a/patchwork/views/cover.py b/patchwork/views/cover.py
index af1b2f2..21bfde2 100644
--- a/patchwork/views/cover.py
+++ b/patchwork/views/cover.py
@@ -17,12 +17,12 @@
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from django.core import urlresolvers
from django.http import Http404
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render_to_response
+from patchwork.compat import reverse
from patchwork.models import CoverLetter
from patchwork.models import Submission
@@ -35,9 +35,7 @@ def cover_detail(request, cover_id):
submissions = Submission.objects.filter(id=cover_id)
if submissions:
return HttpResponseRedirect(
- urlresolvers.reverse(
- 'patch-detail',
- kwargs={'patch_id': cover_id}))
+ reverse('patch-detail', kwargs={'patch_id': cover_id}))
raise exc
context = {
diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py
index 0875d34..49c7972 100644
--- a/patchwork/views/mail.py
+++ b/patchwork/views/mail.py
@@ -21,11 +21,11 @@ import smtplib
from django.conf import settings as conf_settings
from django.core.mail import send_mail
-from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render
from patchwork.compat import render_to_string
+from patchwork.compat import reverse
from patchwork.forms import EmailForm
from patchwork.models import EmailConfirmation
from patchwork.models import EmailOptout
diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py
index 4c1a363..5dafd65 100644
--- a/patchwork/views/patch.py
+++ b/patchwork/views/patch.py
@@ -18,7 +18,6 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from django.contrib import messages
-from django.core import urlresolvers
from django.http import Http404
from django.http import HttpResponse
from django.http import HttpResponseForbidden
@@ -26,6 +25,7 @@ from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render
+from patchwork.compat import reverse
from patchwork.forms import CreateBundleForm
from patchwork.forms import PatchForm
from patchwork.models import Bundle
@@ -52,9 +52,7 @@ def patch_detail(request, patch_id):
submissions = Submission.objects.filter(id=patch_id)
if submissions:
return HttpResponseRedirect(
- urlresolvers.reverse(
- 'cover-detail',
- kwargs={'cover_id': patch_id}))
+ reverse('cover-detail', kwargs={'cover_id': patch_id}))
raise exc
editable = patch.is_editable(request.user)
diff --git a/patchwork/views/project.py b/patchwork/views/project.py
index 6184805..484455c 100644
--- a/patchwork/views/project.py
+++ b/patchwork/views/project.py
@@ -19,11 +19,11 @@
from django.conf import settings
from django.contrib.auth.models import User
-from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render
+from patchwork.compat import reverse
from patchwork.models import Patch
from patchwork.models import Project
@@ -33,8 +33,8 @@ def project_list(request):
if projects.count() == 1:
return HttpResponseRedirect(
- urlresolvers.reverse('patch-list',
- kwargs={'project_id': projects[0].linkname}))
+ reverse('patch-list',
+ kwargs={'project_id': projects[0].linkname}))
context = {
'projects': projects,
diff --git a/patchwork/views/user.py b/patchwork/views/user.py
index 7c29087..375d3d9 100644
--- a/patchwork/views/user.py
+++ b/patchwork/views/user.py
@@ -24,12 +24,12 @@ from django.contrib.auth.decorators import login_required
from django.contrib.sites.models import Site
from django.conf import settings
from django.core.mail import send_mail
-from django.core import urlresolvers
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.shortcuts import render
from patchwork.compat import render_to_string
+from patchwork.compat import reverse
from patchwork.filters import DelegateFilter
from patchwork.forms import EmailForm
from patchwork.forms import RegistrationForm
@@ -188,7 +188,7 @@ def unlink(request, person_id):
person.user = None
person.save()
- return HttpResponseRedirect(urlresolvers.reverse('user-profile'))
+ return HttpResponseRedirect(reverse('user-profile'))
@login_required
@@ -204,7 +204,7 @@ def todo_lists(request):
if len(todo_lists) == 1:
return HttpResponseRedirect(
- urlresolvers.reverse(
+ reverse(
'user-todo',
kwargs={'project_id': todo_lists[0]['project'].linkname}))
diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py
index 927ec9c..8de9d10 100644
--- a/patchwork/views/xmlrpc.py
+++ b/patchwork/views/xmlrpc.py
@@ -30,7 +30,6 @@ except ImportError:
from xmlrpc.server import XMLRPCDocGenerator
import sys
-from django.core.urlresolvers import reverse
from django.contrib.auth import authenticate
from django.http import HttpResponse
from django.http import HttpResponseRedirect
@@ -40,6 +39,7 @@ from django.utils import six
from django.utils.six.moves import xmlrpc_client
from django.utils.six.moves.xmlrpc_server import SimpleXMLRPCDispatcher
+from patchwork.compat import reverse
from patchwork.models import Check
from patchwork.models import Patch
from patchwork.models import Person
--
2.9.3
More information about the Patchwork
mailing list