From 97c316b62e88f9d5a9b03487a3b82c93984ab7bb Mon Sep 17 00:00:00 2001 From: Bartuccio Antoine Date: Sun, 6 Oct 2019 01:34:21 +0200 Subject: [PATCH] django2.2: replace removed is_anonymous() and is_authenticated to their now used counterparts --- core/middleware.py | 2 +- core/templates/core/base.jinja | 2 +- core/templates/core/login.jinja | 2 +- core/views/__init__.py | 2 +- core/views/files.py | 2 +- core/views/user.py | 2 +- counter/views.py | 8 ++++---- eboutic/views.py | 10 +++++----- election/views.py | 4 ++-- launderette/views.py | 2 +- sas/views.py | 8 ++++---- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/core/middleware.py b/core/middleware.py index 37c01ff9..54d7dd2e 100644 --- a/core/middleware.py +++ b/core/middleware.py @@ -37,7 +37,7 @@ AnonymousUser = getattr(importlib.import_module(module), klass) def get_cached_user(request): if not hasattr(request, "_cached_user"): user = get_user(request) - if user.is_anonymous(): + if user.is_anonymous: user = AnonymousUser(request) request._cached_user = user diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 43d2a058..0f07b50e 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -39,7 +39,7 @@
- {% if not user.is_authenticated() %} + {% if not user.is_authenticated %} diff --git a/core/templates/core/login.jinja b/core/templates/core/login.jinja index 35efa68c..a81528b6 100644 --- a/core/templates/core/login.jinja +++ b/core/templates/core/login.jinja @@ -11,7 +11,7 @@ {% endif %} {% if next %} - {% if user.is_authenticated() %} + {% if user.is_authenticated %}

{% trans %}Your account doesn't have access to this page. To proceed, please login with an account that has access.{% endtrans %}

{% else %} diff --git a/core/views/__init__.py b/core/views/__init__.py index a9e0a017..bdf76455 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -150,7 +150,7 @@ class CanCreateMixin(View): def dispatch(self, request, *arg, **kwargs): res = super(CanCreateMixin, self).dispatch(request, *arg, **kwargs) - if not request.user.is_authenticated(): + if not request.user.is_authenticated: raise PermissionDenied return res diff --git a/core/views/files.py b/core/views/files.py index 4117dc2d..1ed98946 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -289,7 +289,7 @@ class FileView(CanViewMixin, DetailView, FormMixin): self.form = self.get_form() # The form handle only the file upload files = request.FILES.getlist("file_field") if ( - request.user.is_authenticated() + request.user.is_authenticated and request.user.can_edit(self.object) and self.form.is_valid() ): diff --git a/core/views/user.py b/core/views/user.py index bd3b00ab..1b4ebdf4 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -689,7 +689,7 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView): files = request.FILES.items() self.form.process(files) if ( - request.user.is_authenticated() + request.user.is_authenticated and request.user.can_edit(self.object) and self.form.is_valid() ): diff --git a/counter/views.py b/counter/views.py index 48ebd74b..ce6693e0 100644 --- a/counter/views.py +++ b/counter/views.py @@ -323,7 +323,7 @@ class CounterMain( ) if self.object.type == "BAR": kwargs["barmen"] = self.object.get_barmen_list() - elif self.request.user.is_authenticated(): + elif self.request.user.is_authenticated: kwargs["barmen"] = [self.request.user] if "last_basket" in self.request.session.keys(): kwargs["last_basket"] = self.request.session.pop("last_basket") @@ -372,7 +372,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): ): raise PermissionDenied else: - if not request.user.is_authenticated(): + if not request.user.is_authenticated: raise PermissionDenied return super(CounterClick, self).dispatch(request, *args, **kwargs) @@ -387,7 +387,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): request.session["no_age"] = False self.refill_form = None ret = super(CounterClick, self).get(request, *args, **kwargs) - if (self.object.type != "BAR" and not request.user.is_authenticated()) or ( + if (self.object.type != "BAR" and not request.user.is_authenticated) or ( self.object.type == "BAR" and len(self.object.get_barmen_list()) < 1 ): # Check that at least one barman is logged in ret = self.cancel(request) # Otherwise, go to main view @@ -397,7 +397,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): """ Handle the many possibilities of the post request """ self.object = self.get_object() self.refill_form = None - if (self.object.type != "BAR" and not request.user.is_authenticated()) or ( + if (self.object.type != "BAR" and not request.user.is_authenticated) or ( self.object.type == "BAR" and len(self.object.get_barmen_list()) < 1 ): # Check that at least one barman is logged in return self.cancel(request) diff --git a/eboutic/views.py b/eboutic/views.py index 927f01a3..21a8fead 100644 --- a/eboutic/views.py +++ b/eboutic/views.py @@ -56,7 +56,7 @@ class EbouticMain(TemplateView): request.session.modified = True def get(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseRedirect( reverse_lazy("core:login", args=self.args, kwargs=kwargs) + "?next=" @@ -67,7 +67,7 @@ class EbouticMain(TemplateView): return super(EbouticMain, self).get(request, *args, **kwargs) def post(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseRedirect( reverse_lazy("core:login", args=self.args, kwargs=kwargs) + "?next=" @@ -118,7 +118,7 @@ class EbouticCommand(TemplateView): template_name = "eboutic/eboutic_makecommand.jinja" def get(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseRedirect( reverse_lazy("core:login", args=self.args, kwargs=kwargs) + "?next=" @@ -129,7 +129,7 @@ class EbouticCommand(TemplateView): ) def post(self, request, *args, **kwargs): - if not request.user.is_authenticated(): + if not request.user.is_authenticated: return HttpResponseRedirect( reverse_lazy("core:login", args=self.args, kwargs=kwargs) + "?next=" @@ -192,7 +192,7 @@ class EbouticPayWithSith(TemplateView): with transaction.atomic(): if ( "basket_id" not in request.session.keys() - or not request.user.is_authenticated() + or not request.user.is_authenticated ): return HttpResponseRedirect( reverse_lazy("eboutic:main", args=self.args, kwargs=kwargs) diff --git a/election/views.py b/election/views.py index 22971b62..a730c011 100644 --- a/election/views.py +++ b/election/views.py @@ -553,7 +553,7 @@ class CandidatureUpdateView(CanEditMixin, UpdateView): self.form = self.get_form() self.remove_fields() if ( - request.user.is_authenticated() + request.user.is_authenticated and request.user.can_edit(self.object) and self.form.is_valid() ): @@ -597,7 +597,7 @@ class RoleUpdateView(CanEditMixin, UpdateView): self.form = self.get_form() self.remove_fields() if ( - request.user.is_authenticated() + request.user.is_authenticated and request.user.can_edit(self.object) and self.form.is_valid() ): diff --git a/launderette/views.py b/launderette/views.py index dcf0ffda..5c7e85a8 100644 --- a/launderette/views.py +++ b/launderette/views.py @@ -84,7 +84,7 @@ class LaunderetteBookView(CanViewMixin, DetailView): self.object = self.get_object() if "slot_type" in request.POST.keys(): self.slot_type = request.POST["slot_type"] - if "slot" in request.POST.keys() and request.user.is_authenticated(): + if "slot" in request.POST.keys() and request.user.is_authenticated: self.subscriber = request.user if self.subscriber.is_subscribed: self.date = dateparse.parse_datetime(request.POST["slot"]).replace( diff --git a/sas/views.py b/sas/views.py index d2f7b889..91d0518d 100644 --- a/sas/views.py +++ b/sas/views.py @@ -117,7 +117,7 @@ class SASMainView(FormView): parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() files = request.FILES.getlist("images") root = User.objects.filter(username="root").first() - if request.user.is_authenticated() and request.user.is_in_group( + if request.user.is_authenticated and request.user.is_in_group( settings.SITH_GROUP_SAS_ADMIN_ID ): if self.form.is_valid(): @@ -176,7 +176,7 @@ class PictureView(CanViewMixin, DetailView, FormMixin): def post(self, request, *args, **kwargs): self.object = self.get_object() self.form = self.get_form() - if request.user.is_authenticated() and request.user.was_subscribed: + if request.user.is_authenticated and request.user.was_subscribed: if self.form.is_valid(): for uid in self.form.cleaned_data["users"]: u = User.objects.filter(id=uid).first() @@ -233,7 +233,7 @@ class AlbumUploadView(CanViewMixin, DetailView, FormMixin): self.form = self.get_form() parent = SithFile.objects.filter(id=self.object.id).first() files = request.FILES.getlist("images") - if request.user.is_authenticated() and request.user.is_subscribed: + if request.user.is_authenticated and request.user.is_subscribed: if self.form.is_valid(): self.form.process( parent=parent, @@ -279,7 +279,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin): FileView.handle_clipboard(request, self.object) parent = SithFile.objects.filter(id=self.object.id).first() files = request.FILES.getlist("images") - if request.user.is_authenticated() and request.user.is_subscribed: + if request.user.is_authenticated and request.user.is_subscribed: if self.form.is_valid(): self.form.process( parent=parent,