Renaming IsAuthenticated

This commit is contained in:
reverend 2020-09-13 10:56:18 +02:00
parent e77edf18ac
commit c2d678847e
4 changed files with 15 additions and 15 deletions

View File

@ -8,7 +8,7 @@ from lostplaces_app.models import Place
from django.contrib.auth.models import User
class TestIsAuthenticated(TestCase):
class TestIsAuthenticatedMixin(TestCase):
@classmethod
def setUpTestData(cls):
@ -45,7 +45,7 @@ class TestIsAuthenticated(TestCase):
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
status_code=302,
target_status_code=200,
msg_prefix='''Accesing an IsAuthenticated view while not logged should
msg_prefix='''Accesing an IsAuthenticatedMixin view while not logged should
redirect to login page with redirect params
''',
fetch_redirect_response=True

View File

@ -11,7 +11,7 @@ from django.urls import reverse_lazy
from lostplaces_app.models import Place
class IsAuthenticated(LoginRequiredMixin, View):
class IsAuthenticatedMixin(LoginRequiredMixin, View):
'''
A view mixin that checks wether a user is loged in or not.
If the user is not logged in, he gets redirected to
@ -55,7 +55,7 @@ class IsPlaceSubmitter(UserPassesTestMixin, View):
messages.error(self.request, self.place_submitter_error_message)
return False
class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
model = None
fields = []
template_name = ''
@ -81,7 +81,7 @@ class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
def get_success_url(self):
return reverse_lazy('place_detail', kwargs={'pk': self.place.id})
class PlaceAssetDeleteView(IsAuthenticated, IsPlaceSubmitter, SingleObjectMixin, View):
class PlaceAssetDeleteView(IsAuthenticatedMixin, IsPlaceSubmitter, SingleObjectMixin, View):
model = None
success_message = ''
permission_denied_message = ''

View File

@ -10,12 +10,12 @@ from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from lostplaces_app.models import Place, PlaceImage
from lostplaces_app.views import IsAuthenticated, IsPlaceSubmitter
from lostplaces_app.views import IsAuthenticatedMixin, IsPlaceSubmitter
from lostplaces_app.forms import PlaceForm, PlaceImageCreateForm, TagSubmitForm
from taggit.models import Tag
class PlaceListView(IsAuthenticated, ListView):
class PlaceListView(IsAuthenticatedMixin, ListView):
paginate_by = 5
model = Place
template_name = 'place/place_list.html'
@ -29,7 +29,7 @@ class PlaceListView(IsAuthenticated, ListView):
}
return context
class PlaceDetailView(IsAuthenticated, View):
class PlaceDetailView(IsAuthenticatedMixin, View):
def get(self, request, pk):
place = Place.objects.get(pk=pk)
context = {
@ -48,7 +48,7 @@ class PlaceDetailView(IsAuthenticated, View):
}
return render(request, 'place/place_detail.html', context)
class PlaceUpdateView(IsAuthenticated, IsPlaceSubmitter, SuccessMessageMixin, UpdateView):
class PlaceUpdateView(IsAuthenticatedMixin, IsPlaceSubmitter, SuccessMessageMixin, UpdateView):
template_name = 'place/place_update.html'
model = Place
form_class = PlaceForm
@ -61,7 +61,7 @@ class PlaceUpdateView(IsAuthenticated, IsPlaceSubmitter, SuccessMessageMixin, Up
def get_place(self):
return self.get_object()
class PlaceCreateView(IsAuthenticated, View):
class PlaceCreateView(IsAuthenticatedMixin, View):
def get(self, request, *args, **kwargs):
place_image_form = PlaceImageCreateForm()
@ -117,7 +117,7 @@ class PlaceCreateView(IsAuthenticated, View):
)
place_image.save()
class PlaceDeleteView(IsAuthenticated, IsPlaceSubmitter, DeleteView):
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitter, DeleteView):
template_name = 'place/place_delete.html'
model = Place
success_message = 'Successfully deleted place.'

View File

@ -9,7 +9,7 @@ from django.http import HttpResponseForbidden
from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm
from lostplaces_app.models import Place, PhotoAlbum
from lostplaces_app.views.base_views import IsAuthenticated
from lostplaces_app.views.base_views import IsAuthenticatedMixin
from lostplaces_app.views.base_views import (
PlaceAssetCreateView,
@ -24,7 +24,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
template_name = 'signup.html'
success_message = 'User created.'
class HomeView(IsAuthenticated, View):
class HomeView(IsAuthenticatedMixin, View):
def get(self, request, *args, **kwargs):
place_list = Place.objects.all().order_by('-submitted_when')[:10]
context = {
@ -55,7 +55,7 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView):
success_message = 'Photo Album deleted'
permission_denied_messsage = 'You do not have permissions to alter this photo album'
class PlaceTagSubmitView(IsAuthenticated, View):
class PlaceTagSubmitView(IsAuthenticatedMixin, View):
def post(self, request, tagged_id, *args, **kwargs):
place = Place.objects.get(pk=tagged_id)
form = TagSubmitForm(request.POST)
@ -70,7 +70,7 @@ class PlaceTagSubmitView(IsAuthenticated, View):
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
class PlaceTagDeleteView(IsAuthenticated, View):
class PlaceTagDeleteView(IsAuthenticatedMixin, View):
def get(self, request, tagged_id, tag_id, *args, **kwargs):
place = Place.objects.get(pk=tagged_id)
tag = Tag.objects.get(pk=tag_id)