Renaming IsAuthenticated
This commit is contained in:
parent
e77edf18ac
commit
c2d678847e
@ -8,7 +8,7 @@ from lostplaces_app.models import Place
|
|||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
class TestIsAuthenticated(TestCase):
|
class TestIsAuthenticatedMixin(TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -45,7 +45,7 @@ class TestIsAuthenticated(TestCase):
|
|||||||
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
|
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
|
||||||
status_code=302,
|
status_code=302,
|
||||||
target_status_code=200,
|
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
|
redirect to login page with redirect params
|
||||||
''',
|
''',
|
||||||
fetch_redirect_response=True
|
fetch_redirect_response=True
|
||||||
|
@ -11,7 +11,7 @@ from django.urls import reverse_lazy
|
|||||||
|
|
||||||
from lostplaces_app.models import Place
|
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.
|
A view mixin that checks wether a user is loged in or not.
|
||||||
If the user is not logged in, he gets redirected to
|
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)
|
messages.error(self.request, self.place_submitter_error_message)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
|
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
|
||||||
model = None
|
model = None
|
||||||
fields = []
|
fields = []
|
||||||
template_name = ''
|
template_name = ''
|
||||||
@ -81,7 +81,7 @@ class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse_lazy('place_detail', kwargs={'pk': self.place.id})
|
return reverse_lazy('place_detail', kwargs={'pk': self.place.id})
|
||||||
|
|
||||||
class PlaceAssetDeleteView(IsAuthenticated, IsPlaceSubmitter, SingleObjectMixin, View):
|
class PlaceAssetDeleteView(IsAuthenticatedMixin, IsPlaceSubmitter, SingleObjectMixin, View):
|
||||||
model = None
|
model = None
|
||||||
success_message = ''
|
success_message = ''
|
||||||
permission_denied_message = ''
|
permission_denied_message = ''
|
||||||
|
@ -10,12 +10,12 @@ from django.shortcuts import render, redirect
|
|||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from lostplaces_app.models import Place, PlaceImage
|
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 lostplaces_app.forms import PlaceForm, PlaceImageCreateForm, TagSubmitForm
|
||||||
|
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
|
||||||
class PlaceListView(IsAuthenticated, ListView):
|
class PlaceListView(IsAuthenticatedMixin, ListView):
|
||||||
paginate_by = 5
|
paginate_by = 5
|
||||||
model = Place
|
model = Place
|
||||||
template_name = 'place/place_list.html'
|
template_name = 'place/place_list.html'
|
||||||
@ -29,7 +29,7 @@ class PlaceListView(IsAuthenticated, ListView):
|
|||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class PlaceDetailView(IsAuthenticated, View):
|
class PlaceDetailView(IsAuthenticatedMixin, View):
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
place = Place.objects.get(pk=pk)
|
place = Place.objects.get(pk=pk)
|
||||||
context = {
|
context = {
|
||||||
@ -48,7 +48,7 @@ class PlaceDetailView(IsAuthenticated, View):
|
|||||||
}
|
}
|
||||||
return render(request, 'place/place_detail.html', context)
|
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'
|
template_name = 'place/place_update.html'
|
||||||
model = Place
|
model = Place
|
||||||
form_class = PlaceForm
|
form_class = PlaceForm
|
||||||
@ -61,7 +61,7 @@ class PlaceUpdateView(IsAuthenticated, IsPlaceSubmitter, SuccessMessageMixin, Up
|
|||||||
def get_place(self):
|
def get_place(self):
|
||||||
return self.get_object()
|
return self.get_object()
|
||||||
|
|
||||||
class PlaceCreateView(IsAuthenticated, View):
|
class PlaceCreateView(IsAuthenticatedMixin, View):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
place_image_form = PlaceImageCreateForm()
|
place_image_form = PlaceImageCreateForm()
|
||||||
@ -117,7 +117,7 @@ class PlaceCreateView(IsAuthenticated, View):
|
|||||||
)
|
)
|
||||||
place_image.save()
|
place_image.save()
|
||||||
|
|
||||||
class PlaceDeleteView(IsAuthenticated, IsPlaceSubmitter, DeleteView):
|
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitter, DeleteView):
|
||||||
template_name = 'place/place_delete.html'
|
template_name = 'place/place_delete.html'
|
||||||
model = Place
|
model = Place
|
||||||
success_message = 'Successfully deleted place.'
|
success_message = 'Successfully deleted place.'
|
||||||
|
@ -9,7 +9,7 @@ from django.http import HttpResponseForbidden
|
|||||||
|
|
||||||
from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm
|
from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm
|
||||||
from lostplaces_app.models import Place, PhotoAlbum
|
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 (
|
from lostplaces_app.views.base_views import (
|
||||||
PlaceAssetCreateView,
|
PlaceAssetCreateView,
|
||||||
@ -24,7 +24,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
|
|||||||
template_name = 'signup.html'
|
template_name = 'signup.html'
|
||||||
success_message = 'User created.'
|
success_message = 'User created.'
|
||||||
|
|
||||||
class HomeView(IsAuthenticated, View):
|
class HomeView(IsAuthenticatedMixin, View):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
place_list = Place.objects.all().order_by('-submitted_when')[:10]
|
place_list = Place.objects.all().order_by('-submitted_when')[:10]
|
||||||
context = {
|
context = {
|
||||||
@ -55,7 +55,7 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView):
|
|||||||
success_message = 'Photo Album deleted'
|
success_message = 'Photo Album deleted'
|
||||||
permission_denied_messsage = 'You do not have permissions to alter this photo album'
|
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):
|
def post(self, request, tagged_id, *args, **kwargs):
|
||||||
place = Place.objects.get(pk=tagged_id)
|
place = Place.objects.get(pk=tagged_id)
|
||||||
form = TagSubmitForm(request.POST)
|
form = TagSubmitForm(request.POST)
|
||||||
@ -70,7 +70,7 @@ class PlaceTagSubmitView(IsAuthenticated, View):
|
|||||||
|
|
||||||
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
|
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):
|
def get(self, request, tagged_id, tag_id, *args, **kwargs):
|
||||||
place = Place.objects.get(pk=tagged_id)
|
place = Place.objects.get(pk=tagged_id)
|
||||||
tag = Tag.objects.get(pk=tag_id)
|
tag = Tag.objects.get(pk=tag_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user