]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
compat: Handle is_authenticated move to property
authorStephen Finucane <stephen@that.guru>
Thu, 18 May 2017 20:17:46 +0000 (21:17 +0100)
committerStephen Finucane <stephen@that.guru>
Thu, 18 May 2017 20:17:46 +0000 (21:17 +0100)
This raises a warning in Django 1.10 and will cause an error in 2.0.

This resolves all issues with Django 1.9.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/api/bundle.py
patchwork/compat.py
patchwork/models.py
patchwork/paginator.py
patchwork/views/__init__.py
patchwork/views/patch.py

index 5fa79b8a96be4d23c9da217469a635f288bb4eeb..88d74a5dd480a92d06d8795f0a6f1a5279730de2 100644 (file)
@@ -25,6 +25,7 @@ from rest_framework.serializers import SerializerMethodField
 
 from patchwork.api.base import PatchworkPermission
 from patchwork.api.filters import BundleFilter
+from patchwork.compat import is_authenticated
 from patchwork.models import Bundle
 
 
@@ -55,7 +56,7 @@ class BundleMixin(object):
     serializer_class = BundleSerializer
 
     def get_queryset(self):
-        if not self.request.user.is_anonymous():
+        if is_authenticated(self.request.user):
             bundle_filter = Q(owner=self.request.user) | Q(public=True)
         else:
             bundle_filter = Q(public=True)
index cd4da4c90951fae439146dbebf9904be97b72fb0..38a844d93d03f68e81ffde3e5c8f78be7e54014b 100644 (file)
@@ -89,3 +89,17 @@ if django.VERSION >= (1, 10):
 else:
     from django.core.urlresolvers import NoReverseMatch  # noqa
     from django.core.urlresolvers import reverse  # noqa
+
+
+# is_authenticated
+#
+# models.User.is_authenticated is now an attribute in Django 1.10 instead of a
+# function
+#
+# https://docs.djangoproject.com/en/dev/releases/1.10/
+
+def is_authenticated(user):
+    if django.VERSION >= (1, 10):
+        return user.is_authenticated
+    else:
+        return user.is_authenticated()
index 725d0b0bf3677bb604bb5a73e0701965e6d4b090..bb8398b40122c76e7befa7543783e60bfb99b30b 100644 (file)
@@ -33,6 +33,7 @@ from django.db import models
 from django.utils.encoding import python_2_unicode_compatible
 from django.utils.functional import cached_property
 
+from patchwork.compat import is_authenticated
 from patchwork.fields import HashField
 from patchwork.hasher import hash_diff
 
@@ -81,7 +82,7 @@ class Project(models.Model):
     use_tags = models.BooleanField(default=True)
 
     def is_editable(self, user):
-        if not user.is_authenticated():
+        if not is_authenticated(user):
             return False
         return self in user.profile.maintainer_projects.all()
 
@@ -423,7 +424,7 @@ class Patch(SeriesMixin, Submission):
         self.refresh_tag_counts()
 
     def is_editable(self, user):
-        if not user.is_authenticated():
+        if not is_authenticated(user):
             return False
 
         if user in [self.submitter.user, self.delegate]:
index 526a3285c417091e6c52477fb97ed82150fcce11..609e908c2cbf55d1687b6e69065f2cba033e5a81 100644 (file)
@@ -22,6 +22,8 @@ from __future__ import absolute_import
 from django.conf import settings
 from django.core import paginator
 
+from patchwork.compat import is_authenticated
+
 
 DEFAULT_ITEMS_PER_PAGE = 100
 LONG_PAGE_THRESHOLD = 30
@@ -42,7 +44,7 @@ class Paginator(paginator.Paginator):
 
         items_per_page = settings.DEFAULT_ITEMS_PER_PAGE
 
-        if request.user.is_authenticated():
+        if is_authenticated(request.user):
             items_per_page = request.user.profile.items_per_page
 
         super(Paginator, self).__init__(objects, items_per_page)
index c8845150cbb105b78d4d7643963b35da6542ca7a..3baf2999a83654e7f2bc1bf00197e7a2692545fa 100644 (file)
@@ -20,6 +20,7 @@
 from django.contrib import messages
 from django.shortcuts import get_object_or_404
 
+from patchwork.compat import is_authenticated
 from patchwork.filters import Filters
 from patchwork.forms import MultiplePatchForm
 from patchwork.models import Bundle
@@ -229,7 +230,7 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
     user = request.user
     properties_form = None
 
-    if user.is_authenticated():
+    if is_authenticated(user):
         # we only pass the post data to the MultiplePatchForm if that was
         # the actual form submitted
         data_tmp = None
index 5dafd65b7b1af4c9d6ab75a4c9fccd9ce7e0d648..09705ef4b518defe3d7962c87b2788dc01dece7b 100644 (file)
@@ -26,6 +26,7 @@ from django.shortcuts import get_object_or_404
 from django.shortcuts import render
 
 from patchwork.compat import reverse
+from patchwork.compat import is_authenticated
 from patchwork.forms import CreateBundleForm
 from patchwork.forms import PatchForm
 from patchwork.models import Bundle
@@ -65,7 +66,7 @@ def patch_detail(request, patch_id):
 
     if editable:
         form = PatchForm(instance=patch)
-    if request.user.is_authenticated():
+    if is_authenticated(request.user):
         createbundleform = CreateBundleForm()
 
     if request.method == 'POST':
@@ -106,7 +107,7 @@ def patch_detail(request, patch_id):
                 form.save()
                 messages.success(request, 'Patch updated')
 
-    if request.user.is_authenticated():
+    if is_authenticated(request.user):
         context['bundles'] = Bundle.objects.filter(owner=request.user)
 
     context['submission'] = patch