Compare commits

..

No commits in common. "9852646fff14ccbbee306cba5e05b3db98e130de" and "e77edf18ac861c03bbf3cb59d68237997575796a" have entirely different histories.

4 changed files with 17 additions and 17 deletions

View File

@ -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 TestIsAuthenticatedMixin(TestCase): class TestIsAuthenticated(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
@ -45,7 +45,7 @@ class TestIsAuthenticatedMixin(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 IsAuthenticatedMixin view while not logged should msg_prefix='''Accesing an IsAuthenticated 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
@ -53,7 +53,7 @@ class TestIsAuthenticatedMixin(TestCase):
self.assertTrue(response.context['messages']) self.assertTrue(response.context['messages'])
self.assertTrue(len(response.context['messages']) > 0) self.assertTrue(len(response.context['messages']) > 0)
class TestIsPlaceSubmitterMixin(TestCase): class TestIsPlaceSubmitter(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):

View File

@ -11,7 +11,7 @@ from django.urls import reverse_lazy
from lostplaces_app.models import Place from lostplaces_app.models import Place
class IsAuthenticatedMixin(LoginRequiredMixin, View): class IsAuthenticated(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
@ -24,7 +24,7 @@ class IsAuthenticatedMixin(LoginRequiredMixin, View):
messages.error(self.request, self.permission_denied_message) messages.error(self.request, self.permission_denied_message)
return super().handle_no_permission() return super().handle_no_permission()
class IsPlaceSubmitterMixin(UserPassesTestMixin, View): class IsPlaceSubmitter(UserPassesTestMixin, View):
''' '''
A view mixin that checks wethe a user is the submitter A view mixin that checks wethe a user is the submitter
of a place Throws 403 if the user is not. The subclass of a place Throws 403 if the user is not. The subclass
@ -55,7 +55,7 @@ class IsPlaceSubmitterMixin(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(IsAuthenticatedMixin, SuccessMessageMixin, CreateView): class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
model = None model = None
fields = [] fields = []
template_name = '' template_name = ''
@ -81,7 +81,7 @@ class PlaceAssetCreateView(IsAuthenticatedMixin, 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(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SingleObjectMixin, View): class PlaceAssetDeleteView(IsAuthenticated, IsPlaceSubmitter, SingleObjectMixin, View):
model = None model = None
success_message = '' success_message = ''
permission_denied_message = '' permission_denied_message = ''

View File

@ -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 IsAuthenticatedMixin, IsPlaceSubmitterMixin from lostplaces_app.views import IsAuthenticated, 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(IsAuthenticatedMixin, ListView): class PlaceListView(IsAuthenticated, 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(IsAuthenticatedMixin, ListView):
} }
return context return context
class PlaceDetailView(IsAuthenticatedMixin, View): class PlaceDetailView(IsAuthenticated, 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(IsAuthenticatedMixin, View):
} }
return render(request, 'place/place_detail.html', context) return render(request, 'place/place_detail.html', context)
class PlaceUpdateView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SuccessMessageMixin, UpdateView): class PlaceUpdateView(IsAuthenticated, 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(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SuccessMessag
def get_place(self): def get_place(self):
return self.get_object() return self.get_object()
class PlaceCreateView(IsAuthenticatedMixin, View): class PlaceCreateView(IsAuthenticated, 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(IsAuthenticatedMixin, View):
) )
place_image.save() place_image.save()
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView): class PlaceDeleteView(IsAuthenticated, 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.'

View File

@ -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 IsAuthenticatedMixin from lostplaces_app.views.base_views import IsAuthenticated
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(IsAuthenticatedMixin, View): class HomeView(IsAuthenticated, 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(IsAuthenticatedMixin, View): class PlaceTagSubmitView(IsAuthenticated, 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(IsAuthenticatedMixin, View):
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id})) return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
class PlaceTagDeleteView(IsAuthenticatedMixin, View): class PlaceTagDeleteView(IsAuthenticated, 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)