summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2019-10-14 11:43:08 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2019-10-29 07:35:46 (GMT)
commitccf99d908f3263e7d249738664318b6d8648bea0 (patch)
treeab08ff830624b54fda3279da332102cdef71c5d5
parent49830fc9c5c2c994457fec2525eca81f2de9b26f (diff)
downloadcombo-ccf99d908f3263e7d249738664318b6d8648bea0.zip
combo-ccf99d908f3263e7d249738664318b6d8648bea0.tar.gz
combo-ccf99d908f3263e7d249738664318b6d8648bea0.tar.bz2
dj2: is_anonymous and is_authenticated are now properties (#36895)
remove RemovedInDjango20Warning: Using user.is_authenticated() and user.is_anonymous() as a method is deprecated. Remove the parentheses to use it as an attribute.
-rw-r--r--combo/apps/dashboard/models.py2
-rw-r--r--combo/apps/dashboard/views.py2
-rw-r--r--combo/apps/family/models.py2
-rw-r--r--combo/apps/fargo/models.py2
-rw-r--r--combo/apps/lingo/models.py12
-rw-r--r--combo/apps/lingo/views.py12
-rw-r--r--combo/apps/newsletters/models.py4
-rw-r--r--combo/apps/notifications/models.py6
-rw-r--r--combo/apps/pwa/views.py2
-rw-r--r--combo/apps/wcs/models.py2
-rw-r--r--combo/data/models.py8
-rw-r--r--combo/profile/models.py2
-rw-r--r--combo/profile/utils.py2
-rw-r--r--combo/public/templatetags/combo.py4
-rw-r--r--combo/public/views.py6
-rw-r--r--combo/urls_utils.py2
-rw-r--r--combo/utils/requests_wrapper.py2
-rw-r--r--combo/utils/urls.py2
-rw-r--r--tests/test_lingo_remote_regie.py3
-rw-r--r--tests/test_requests.py3
-rw-r--r--tests/test_utils.py3
-rw-r--r--tests/test_wcs.py8
22 files changed, 45 insertions, 46 deletions
diff --git a/combo/apps/dashboard/models.py b/combo/apps/dashboard/models.py
index 4868be1..bcc9eb8 100644
--- a/combo/apps/dashboard/models.py
+++ b/combo/apps/dashboard/models.py
@@ -40,7 +40,7 @@ class DashboardCell(CellBase):
return settings.COMBO_DASHBOARD_ENABLED
def is_relevant(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return False
return True
diff --git a/combo/apps/dashboard/views.py b/combo/apps/dashboard/views.py
index 1ca10dc..706272b 100644
--- a/combo/apps/dashboard/views.py
+++ b/combo/apps/dashboard/views.py
@@ -50,7 +50,7 @@ def dashboard_success(request, dashboard, cell_data):
class DashboardAddTileView(View):
def get(self, request, *args, **kwargs):
- if not request.user.is_authenticated():
+ if not request.user.is_authenticated:
raise PermissionDenied()
dashboard = DashboardCell.objects.all()[0]
diff --git a/combo/apps/family/models.py b/combo/apps/family/models.py
index 00505ac..63d9f7d 100644
--- a/combo/apps/family/models.py
+++ b/combo/apps/family/models.py
@@ -41,7 +41,7 @@ class FamilyInfosCell(CellBase):
if context.get('placeholder_search_mode'):
return {}
user = self.get_concerned_user(context)
- if not user or user.is_anonymous():
+ if not user or user.is_anonymous:
return {}
response = get_family(user=user,
raise_if_not_cached=not(context.get('synchronous')))
diff --git a/combo/apps/fargo/models.py b/combo/apps/fargo/models.py
index 9801341..32f2a49 100644
--- a/combo/apps/fargo/models.py
+++ b/combo/apps/fargo/models.py
@@ -53,7 +53,7 @@ class RecentDocumentsCell(CellBase):
widgets=self.get_form_widgets())
def is_visible(self, user=None):
- if not user or user.is_anonymous():
+ if not user or user.is_anonymous:
return False
return super(RecentDocumentsCell, self).is_visible(user)
diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py
index b49c1a5..7bbb1ef 100644
--- a/combo/apps/lingo/models.py
+++ b/combo/apps/lingo/models.py
@@ -526,12 +526,12 @@ class LingoBasketCell(CellBase):
return Regie.objects.count() > 0
def is_relevant(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return False
return BasketItem.get_items_to_be_paid(context['request'].user).count() > 0
def get_badge(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return
items = BasketItem.get_items_to_be_paid(context['request'].user)
if not items:
@@ -569,7 +569,7 @@ class LingoRecentTransactionsCell(CellBase):
return Regie.objects.count() > 0
def is_relevant(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return False
transactions = Transaction.objects.filter(
user=context['request'].user,
@@ -598,12 +598,12 @@ class LingoBasketLinkCell(CellBase):
return Regie.objects.count() > 0
def is_relevant(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return False
return BasketItem.get_items_to_be_paid(context['request'].user).count() > 0
def render(self, context):
- if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated()):
+ if not (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated):
return ''
try:
context['basket_url'] = LingoBasketCell.objects.all()[0].page.get_online_url()
@@ -636,7 +636,7 @@ class Items(CellBase):
return Regie.objects.exclude(webservice_url='').count() > 0
def is_relevant(self, context):
- return (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated())
+ return (getattr(context['request'], 'user', None) and context['request'].user.is_authenticated)
def get_default_form_class(self):
fields = ['title', 'text']
diff --git a/combo/apps/lingo/views.py b/combo/apps/lingo/views.py
index 053d7c7..f3f9697 100644
--- a/combo/apps/lingo/views.py
+++ b/combo/apps/lingo/views.py
@@ -332,7 +332,7 @@ class PayMixin(object):
if item.regie != regie:
messages.error(request, _(u'Invalid grouping for basket items.'))
return HttpResponseRedirect(next_url)
- user = request.user if request.user.is_authenticated() else None
+ user = request.user if request.user.is_authenticated else None
transaction = Transaction()
if user:
transaction.user = user
@@ -386,7 +386,7 @@ class PayView(PayMixin, View):
def post(self, request, *args, **kwargs):
regie_id = request.POST.get('regie')
next_url = request.POST.get('next_url') or '/'
- user = request.user if request.user.is_authenticated() else None
+ user = request.user if request.user.is_authenticated else None
remote_items = []
items = []
if regie_id and Regie.objects.get(pk=regie_id).is_remote():
@@ -433,7 +433,7 @@ class PayView(PayMixin, View):
class BasketItemPayView(PayMixin, View):
def get(self, request, *args, **kwargs):
next_url = request.GET.get('next_url') or '/'
- if not (request.user and request.user.is_authenticated()):
+ if not (request.user and request.user.is_authenticated):
return HttpResponseForbidden(_('No item payment allowed for anonymous users.'))
item = BasketItem.objects.get(pk=kwargs['item_id'])
@@ -615,7 +615,7 @@ class ReturnView(PaymentView):
return HttpResponseRedirect(redirect_url)
# return to basket page if there are still items to pay
- if request.user.is_authenticated():
+ if request.user.is_authenticated:
remaining_basket_items = BasketItem.get_items_to_be_paid(
user=self.request.user).count()
if remaining_basket_items:
@@ -699,11 +699,11 @@ class CancelItemView(DetailView):
return context
def get_queryset(self):
- user = self.request.user if self.request.user.is_authenticated() else None
+ user = self.request.user if self.request.user.is_authenticated else None
return BasketItem.get_items_to_be_paid(user=user)
def post(self, request, *args, **kwargs):
- if not request.user.is_authenticated():
+ if not request.user.is_authenticated:
messages.error(request, _('An error occured when removing the item. '
'(no authenticated user)'))
return HttpResponseRedirect(get_basket_url())
diff --git a/combo/apps/newsletters/models.py b/combo/apps/newsletters/models.py
index 6a9feee..13138b1 100644
--- a/combo/apps/newsletters/models.py
+++ b/combo/apps/newsletters/models.py
@@ -136,12 +136,12 @@ class NewslettersCell(CellBase):
def render(self, context):
user = context.get('user')
- if user and user.is_authenticated():
+ if user and user.is_authenticated:
form = NewslettersManageForm(instance=self, request=context['request'])
context['form'] = form
return super(NewslettersCell, self).render(context)
def is_visible(self, user=None):
- if user is None or not user.is_authenticated():
+ if user is None or not user.is_authenticated:
return False
return super(NewslettersCell, self).is_visible(user)
diff --git a/combo/apps/notifications/models.py b/combo/apps/notifications/models.py
index e3bf7a2..21a08fb 100644
--- a/combo/apps/notifications/models.py
+++ b/combo/apps/notifications/models.py
@@ -172,14 +172,14 @@ class NotificationsCell(CellBase):
verbose_name = _('User Notifications')
def is_visible(self, user=None):
- if user is None or not user.is_authenticated():
+ if user is None or not user.is_authenticated:
return False
return super(NotificationsCell, self).is_visible(user)
def get_cell_extra_context(self, context):
extra_context = super(NotificationsCell, self).get_cell_extra_context(context)
user = getattr(context.get('request'), 'user', None)
- if user and user.is_authenticated():
+ if user and user.is_authenticated:
qs = Notification.objects.visible(user)
extra_context['notifications'] = qs
extra_context['new_notifications'] = qs.new()
@@ -189,7 +189,7 @@ class NotificationsCell(CellBase):
def get_badge(self, context):
user = getattr(context.get('request'), 'user', None)
- if not user or not user.is_authenticated():
+ if not user or not user.is_authenticated:
return
new_count = Notification.objects.visible(user).new().count()
if not new_count:
diff --git a/combo/apps/pwa/views.py b/combo/apps/pwa/views.py
index 61ad0c6..0d0493b 100644
--- a/combo/apps/pwa/views.py
+++ b/combo/apps/pwa/views.py
@@ -83,7 +83,7 @@ def service_worker_registration_js(request, *args, **kwargs):
@csrf_exempt
def subscribe_push(request, *args, **kwargs):
- if not (request.user and request.user.is_authenticated()):
+ if not (request.user and request.user.is_authenticated):
return HttpResponseForbidden()
if request.method != 'POST':
return HttpResponseForbidden()
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index c305336..84e7c4f 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -295,7 +295,7 @@ class WcsUserDataBaseCell(WcsDataBaseCell):
abstract = True
def is_visible(self, user=None):
- if not user or user.is_anonymous():
+ if not user or user.is_anonymous:
return False
return super(WcsUserDataBaseCell, self).is_visible(user)
diff --git a/combo/data/models.py b/combo/data/models.py
index 0176a55..b18f3d0 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -67,9 +67,9 @@ class PostException(Exception):
def element_is_visible(element, user=None):
if element.public:
if getattr(element, 'restricted_to_unlogged', None) is True:
- return (user is None or user.is_anonymous())
+ return (user is None or user.is_anonymous)
return True
- if user is None or user.is_anonymous():
+ if user is None or user.is_anonymous:
return False
if user.is_superuser:
return True
@@ -450,7 +450,7 @@ class PageSnapshot(models.Model):
@classmethod
def take(cls, page, request=None, comment=None, deletion=False):
snapshot = cls(page=page, comment=comment)
- if request and not request.user.is_anonymous():
+ if request and not request.user.is_anonymous:
snapshot.user = request.user
if not deletion:
snapshot.serialization = page.get_serialized_page()
@@ -1018,7 +1018,7 @@ class ParametersCell(CellBase):
def get_form(self, request):
from .forms import ParametersForm
- if not request.user.is_anonymous():
+ if not request.user.is_anonymous:
groups = set(request.user.groups.values_list('name', flat=True))
else:
groups = set()
diff --git a/combo/profile/models.py b/combo/profile/models.py
index 1bcc84d..0e1ad4c 100644
--- a/combo/profile/models.py
+++ b/combo/profile/models.py
@@ -46,7 +46,7 @@ class ProfileCell(JsonCellBase):
return '{%% load combo %%}%sapi/users/{{ concerned_user|name_id }}/' % idp.get('url')
def is_visible(self, user=None):
- if not user or user.is_anonymous():
+ if not user or user.is_anonymous:
return False
return super(ProfileCell, self).is_visible(user)
diff --git a/combo/profile/utils.py b/combo/profile/utils.py
index 22cb55e..8432d05 100644
--- a/combo/profile/utils.py
+++ b/combo/profile/utils.py
@@ -32,9 +32,11 @@ class ProxiedUser(object):
def get_name_id(self):
return self.name_id
+ @property
def is_authenticated(self):
return CallableTrue
+ @property
def is_anonymous(self):
return CallableFalse
diff --git a/combo/public/templatetags/combo.py b/combo/public/templatetags/combo.py
index 6730229..fa09d66 100644
--- a/combo/public/templatetags/combo.py
+++ b/combo/public/templatetags/combo.py
@@ -209,7 +209,7 @@ def shown_because_admin(cell, request):
@register.filter(name='has_role')
def has_role(user, groupname):
- if not user or user.is_anonymous():
+ if not user or user.is_anonymous:
return False
return user.groups.filter(name=groupname).exists()
@@ -253,7 +253,7 @@ def signed(obj):
@register.filter
def name_id(user):
- if user and user.is_authenticated():
+ if user and user.is_authenticated:
user_name_id = user.get_name_id()
if user_name_id:
return user_name_id
diff --git a/combo/public/views.py b/combo/public/views.py
index e690754..bf35b5e 100644
--- a/combo/public/views.py
+++ b/combo/public/views.py
@@ -396,7 +396,7 @@ def page(request):
parts = ['index']
if parts == ['index'] and settings.COMBO_INITIAL_LOGIN_PAGE_PATH and (
- request.user and not request.user.is_anonymous()):
+ request.user and not request.user.is_anonymous):
profile, created = Profile.objects.get_or_create(user=request.user)
if not profile.initial_login_view_timestamp:
# first connection of user, record that and redirect to welcome URL
@@ -405,7 +405,7 @@ def page(request):
return HttpResponseRedirect(settings.COMBO_INITIAL_LOGIN_PAGE_PATH)
if parts == ['index'] and settings.COMBO_WELCOME_PAGE_PATH and (
- not request.user or request.user.is_anonymous()):
+ not request.user or request.user.is_anonymous):
if not request.session.setdefault('visited', False):
# first visit, the user is not logged in.
request.session['visited'] = True
@@ -465,7 +465,7 @@ def publish_page(request, page, status=200, template_name=None):
pages = page.get_parents_and_self()
if not page.is_visible(request.user):
- if not request.user.is_authenticated():
+ if not request.user.is_authenticated:
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.build_absolute_uri())
raise PermissionDenied()
diff --git a/combo/urls_utils.py b/combo/urls_utils.py
index 32cd762..fecf770 100644
--- a/combo/urls_utils.py
+++ b/combo/urls_utils.py
@@ -52,7 +52,7 @@ def manager_required(function=None, login_url=None):
def check_manager(user):
if user and user.is_staff:
return True
- if user and not user.is_anonymous():
+ if user and not user.is_anonymous:
raise PermissionDenied()
# As the last resort, show the login form
return False
diff --git a/combo/utils/requests_wrapper.py b/combo/utils/requests_wrapper.py
index 8befd05..4add535 100644
--- a/combo/utils/requests_wrapper.py
+++ b/combo/utils/requests_wrapper.py
@@ -82,7 +82,7 @@ class Requests(RequestsSession):
if remote_service:
if isinstance(user, dict):
query_params = user.copy()
- elif not user or not user.is_authenticated():
+ elif not user or not user.is_authenticated:
if without_user:
query_params = {}
else:
diff --git a/combo/utils/urls.py b/combo/utils/urls.py
index 10703e9..c7f41f3 100644
--- a/combo/utils/urls.py
+++ b/combo/utils/urls.py
@@ -43,7 +43,7 @@ def get_templated_url(url, context=None):
template_vars['user_email'] = ''
template_vars['user_nameid'] = ''
user = getattr(context.get('request'), 'user', None)
- if user and user.is_authenticated():
+ if user and user.is_authenticated:
template_vars['user_email'] = quote(user.email)
user_nameid = user.get_name_id()
if user_nameid:
diff --git a/tests/test_lingo_remote_regie.py b/tests/test_lingo_remote_regie.py
index 355bb07..d4e2c08 100644
--- a/tests/test_lingo_remote_regie.py
+++ b/tests/test_lingo_remote_regie.py
@@ -76,8 +76,7 @@ def remote_regie():
class MockUser(object):
email = 'foo@example.net'
- def is_authenticated(self):
- return True
+ is_authenticated = True
def get_name_id(self):
return 'r2d2'
diff --git a/tests/test_requests.py b/tests/test_requests.py
index a116cd0..7052269 100644
--- a/tests/test_requests.py
+++ b/tests/test_requests.py
@@ -10,8 +10,7 @@ from combo.utils import requests, check_query, NothingInCacheException
class MockUser(object):
email = 'foo@example.net'
- def is_authenticated(self):
- return True
+ is_authenticated = True
def get_name_id(self):
if self.samlized:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 422b9a8..356bc02 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -11,8 +11,7 @@ from django.contrib.auth.models import AnonymousUser
class MockUser(object):
email = 'foo=3@example.net'
- def is_authenticated(self):
- return True
+ is_authenticated = True
def __init__(self, samlized=True):
self.samlized = samlized
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index 4f03bf9..15d30e2 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -166,16 +166,16 @@ WCS_PID = None
class MockUser(object):
email = 'foo@example.net'
- def is_authenticated(self):
- return True
+ is_authenticated = True
+
def get_name_id(self):
return None
class MockUserWithNameId(object):
email = 'foo@example.net'
- def is_authenticated(self):
- return True
+ is_authenticated = True
+
def get_name_id(self):
return 'xyz'