django2.2: replace removed is_anonymous() and is_authenticated to their now used counterparts

This commit is contained in:
Antoine Bartuccio 2019-10-06 01:34:21 +02:00
parent 90921fd4cd
commit 97c316b62e
Signed by: klmp200
GPG Key ID: E7245548C53F904B
11 changed files with 22 additions and 22 deletions

View File

@ -37,7 +37,7 @@ AnonymousUser = getattr(importlib.import_module(module), klass)
def get_cached_user(request): def get_cached_user(request):
if not hasattr(request, "_cached_user"): if not hasattr(request, "_cached_user"):
user = get_user(request) user = get_user(request)
if user.is_anonymous(): if user.is_anonymous:
user = AnonymousUser(request) user = AnonymousUser(request)
request._cached_user = user request._cached_user = user

View File

@ -39,7 +39,7 @@
</div> </div>
<header> <header>
{% if not user.is_authenticated() %} {% if not user.is_authenticated %}
<div id="header_logo" style="background-image: url('{{ static('core/img/logo.png') }}'); width: 185px; height: 100px;"> <div id="header_logo" style="background-image: url('{{ static('core/img/logo.png') }}'); width: 185px; height: 100px;">
<a href="{{ url('core:index') }}"></a> <a href="{{ url('core:index') }}"></a>
</div> </div>

View File

@ -11,7 +11,7 @@
{% endif %} {% endif %}
{% if next %} {% if next %}
{% if user.is_authenticated() %} {% if user.is_authenticated %}
<p>{% trans %}Your account doesn't have access to this page. To proceed, <p>{% trans %}Your account doesn't have access to this page. To proceed,
please login with an account that has access.{% endtrans %}</p> please login with an account that has access.{% endtrans %}</p>
{% else %} {% else %}

View File

@ -150,7 +150,7 @@ class CanCreateMixin(View):
def dispatch(self, request, *arg, **kwargs): def dispatch(self, request, *arg, **kwargs):
res = super(CanCreateMixin, self).dispatch(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 raise PermissionDenied
return res return res

View File

@ -289,7 +289,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
self.form = self.get_form() # The form handle only the file upload self.form = self.get_form() # The form handle only the file upload
files = request.FILES.getlist("file_field") files = request.FILES.getlist("file_field")
if ( if (
request.user.is_authenticated() request.user.is_authenticated
and request.user.can_edit(self.object) and request.user.can_edit(self.object)
and self.form.is_valid() and self.form.is_valid()
): ):

View File

@ -689,7 +689,7 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
files = request.FILES.items() files = request.FILES.items()
self.form.process(files) self.form.process(files)
if ( if (
request.user.is_authenticated() request.user.is_authenticated
and request.user.can_edit(self.object) and request.user.can_edit(self.object)
and self.form.is_valid() and self.form.is_valid()
): ):

View File

@ -323,7 +323,7 @@ class CounterMain(
) )
if self.object.type == "BAR": if self.object.type == "BAR":
kwargs["barmen"] = self.object.get_barmen_list() kwargs["barmen"] = self.object.get_barmen_list()
elif self.request.user.is_authenticated(): elif self.request.user.is_authenticated:
kwargs["barmen"] = [self.request.user] kwargs["barmen"] = [self.request.user]
if "last_basket" in self.request.session.keys(): if "last_basket" in self.request.session.keys():
kwargs["last_basket"] = self.request.session.pop("last_basket") kwargs["last_basket"] = self.request.session.pop("last_basket")
@ -372,7 +372,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
): ):
raise PermissionDenied raise PermissionDenied
else: else:
if not request.user.is_authenticated(): if not request.user.is_authenticated:
raise PermissionDenied raise PermissionDenied
return super(CounterClick, self).dispatch(request, *args, **kwargs) return super(CounterClick, self).dispatch(request, *args, **kwargs)
@ -387,7 +387,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
request.session["no_age"] = False request.session["no_age"] = False
self.refill_form = None self.refill_form = None
ret = super(CounterClick, self).get(request, *args, **kwargs) 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 self.object.type == "BAR" and len(self.object.get_barmen_list()) < 1
): # Check that at least one barman is logged in ): # Check that at least one barman is logged in
ret = self.cancel(request) # Otherwise, go to main view 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 """ """ Handle the many possibilities of the post request """
self.object = self.get_object() self.object = self.get_object()
self.refill_form = None 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 self.object.type == "BAR" and len(self.object.get_barmen_list()) < 1
): # Check that at least one barman is logged in ): # Check that at least one barman is logged in
return self.cancel(request) return self.cancel(request)

View File

@ -56,7 +56,7 @@ class EbouticMain(TemplateView):
request.session.modified = True request.session.modified = True
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if not request.user.is_authenticated(): if not request.user.is_authenticated:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("core:login", args=self.args, kwargs=kwargs) reverse_lazy("core:login", args=self.args, kwargs=kwargs)
+ "?next=" + "?next="
@ -67,7 +67,7 @@ class EbouticMain(TemplateView):
return super(EbouticMain, self).get(request, *args, **kwargs) return super(EbouticMain, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if not request.user.is_authenticated(): if not request.user.is_authenticated:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("core:login", args=self.args, kwargs=kwargs) reverse_lazy("core:login", args=self.args, kwargs=kwargs)
+ "?next=" + "?next="
@ -118,7 +118,7 @@ class EbouticCommand(TemplateView):
template_name = "eboutic/eboutic_makecommand.jinja" template_name = "eboutic/eboutic_makecommand.jinja"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if not request.user.is_authenticated(): if not request.user.is_authenticated:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("core:login", args=self.args, kwargs=kwargs) reverse_lazy("core:login", args=self.args, kwargs=kwargs)
+ "?next=" + "?next="
@ -129,7 +129,7 @@ class EbouticCommand(TemplateView):
) )
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if not request.user.is_authenticated(): if not request.user.is_authenticated:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("core:login", args=self.args, kwargs=kwargs) reverse_lazy("core:login", args=self.args, kwargs=kwargs)
+ "?next=" + "?next="
@ -192,7 +192,7 @@ class EbouticPayWithSith(TemplateView):
with transaction.atomic(): with transaction.atomic():
if ( if (
"basket_id" not in request.session.keys() "basket_id" not in request.session.keys()
or not request.user.is_authenticated() or not request.user.is_authenticated
): ):
return HttpResponseRedirect( return HttpResponseRedirect(
reverse_lazy("eboutic:main", args=self.args, kwargs=kwargs) reverse_lazy("eboutic:main", args=self.args, kwargs=kwargs)

View File

@ -553,7 +553,7 @@ class CandidatureUpdateView(CanEditMixin, UpdateView):
self.form = self.get_form() self.form = self.get_form()
self.remove_fields() self.remove_fields()
if ( if (
request.user.is_authenticated() request.user.is_authenticated
and request.user.can_edit(self.object) and request.user.can_edit(self.object)
and self.form.is_valid() and self.form.is_valid()
): ):
@ -597,7 +597,7 @@ class RoleUpdateView(CanEditMixin, UpdateView):
self.form = self.get_form() self.form = self.get_form()
self.remove_fields() self.remove_fields()
if ( if (
request.user.is_authenticated() request.user.is_authenticated
and request.user.can_edit(self.object) and request.user.can_edit(self.object)
and self.form.is_valid() and self.form.is_valid()
): ):

View File

@ -84,7 +84,7 @@ class LaunderetteBookView(CanViewMixin, DetailView):
self.object = self.get_object() self.object = self.get_object()
if "slot_type" in request.POST.keys(): if "slot_type" in request.POST.keys():
self.slot_type = request.POST["slot_type"] 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 self.subscriber = request.user
if self.subscriber.is_subscribed: if self.subscriber.is_subscribed:
self.date = dateparse.parse_datetime(request.POST["slot"]).replace( self.date = dateparse.parse_datetime(request.POST["slot"]).replace(

View File

@ -117,7 +117,7 @@ class SASMainView(FormView):
parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
files = request.FILES.getlist("images") files = request.FILES.getlist("images")
root = User.objects.filter(username="root").first() 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 settings.SITH_GROUP_SAS_ADMIN_ID
): ):
if self.form.is_valid(): if self.form.is_valid():
@ -176,7 +176,7 @@ class PictureView(CanViewMixin, DetailView, FormMixin):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
self.form = self.get_form() 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(): if self.form.is_valid():
for uid in self.form.cleaned_data["users"]: for uid in self.form.cleaned_data["users"]:
u = User.objects.filter(id=uid).first() u = User.objects.filter(id=uid).first()
@ -233,7 +233,7 @@ class AlbumUploadView(CanViewMixin, DetailView, FormMixin):
self.form = self.get_form() self.form = self.get_form()
parent = SithFile.objects.filter(id=self.object.id).first() parent = SithFile.objects.filter(id=self.object.id).first()
files = request.FILES.getlist("images") 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(): if self.form.is_valid():
self.form.process( self.form.process(
parent=parent, parent=parent,
@ -279,7 +279,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
FileView.handle_clipboard(request, self.object) FileView.handle_clipboard(request, self.object)
parent = SithFile.objects.filter(id=self.object.id).first() parent = SithFile.objects.filter(id=self.object.id).first()
files = request.FILES.getlist("images") 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(): if self.form.is_valid():
self.form.process( self.form.process(
parent=parent, parent=parent,