Compare commits
No commits in common. "9852646fff14ccbbee306cba5e05b3db98e130de" and "e77edf18ac861c03bbf3cb59d68237997575796a" have entirely different histories.
9852646fff
...
e77edf18ac
@ -8,7 +8,7 @@ from lostplaces_app.models import Place
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class TestIsAuthenticatedMixin(TestCase):
|
||||
class TestIsAuthenticated(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -45,7 +45,7 @@ class TestIsAuthenticatedMixin(TestCase):
|
||||
expected_url='?'.join([str(reverse_lazy('login')), 'next=/place/1/']),
|
||||
status_code=302,
|
||||
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
|
||||
''',
|
||||
fetch_redirect_response=True
|
||||
@ -53,7 +53,7 @@ class TestIsAuthenticatedMixin(TestCase):
|
||||
self.assertTrue(response.context['messages'])
|
||||
self.assertTrue(len(response.context['messages']) > 0)
|
||||
|
||||
class TestIsPlaceSubmitterMixin(TestCase):
|
||||
class TestIsPlaceSubmitter(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
@ -11,7 +11,7 @@ from django.urls import reverse_lazy
|
||||
|
||||
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.
|
||||
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)
|
||||
return super().handle_no_permission()
|
||||
|
||||
class IsPlaceSubmitterMixin(UserPassesTestMixin, View):
|
||||
class IsPlaceSubmitter(UserPassesTestMixin, View):
|
||||
'''
|
||||
A view mixin that checks wethe a user is the submitter
|
||||
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)
|
||||
return False
|
||||
|
||||
class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView):
|
||||
class PlaceAssetCreateView(IsAuthenticated, SuccessMessageMixin, CreateView):
|
||||
model = None
|
||||
fields = []
|
||||
template_name = ''
|
||||
@ -81,7 +81,7 @@ class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('place_detail', kwargs={'pk': self.place.id})
|
||||
|
||||
class PlaceAssetDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SingleObjectMixin, View):
|
||||
class PlaceAssetDeleteView(IsAuthenticated, IsPlaceSubmitter, SingleObjectMixin, View):
|
||||
model = None
|
||||
success_message = ''
|
||||
permission_denied_message = ''
|
||||
|
@ -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 IsAuthenticatedMixin, IsPlaceSubmitterMixin
|
||||
from lostplaces_app.views import IsAuthenticated, IsPlaceSubmitter
|
||||
from lostplaces_app.forms import PlaceForm, PlaceImageCreateForm, TagSubmitForm
|
||||
|
||||
from taggit.models import Tag
|
||||
|
||||
class PlaceListView(IsAuthenticatedMixin, ListView):
|
||||
class PlaceListView(IsAuthenticated, ListView):
|
||||
paginate_by = 5
|
||||
model = Place
|
||||
template_name = 'place/place_list.html'
|
||||
@ -29,7 +29,7 @@ class PlaceListView(IsAuthenticatedMixin, ListView):
|
||||
}
|
||||
return context
|
||||
|
||||
class PlaceDetailView(IsAuthenticatedMixin, View):
|
||||
class PlaceDetailView(IsAuthenticated, View):
|
||||
def get(self, request, pk):
|
||||
place = Place.objects.get(pk=pk)
|
||||
context = {
|
||||
@ -48,7 +48,7 @@ class PlaceDetailView(IsAuthenticatedMixin, View):
|
||||
}
|
||||
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'
|
||||
model = Place
|
||||
form_class = PlaceForm
|
||||
@ -61,7 +61,7 @@ class PlaceUpdateView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SuccessMessag
|
||||
def get_place(self):
|
||||
return self.get_object()
|
||||
|
||||
class PlaceCreateView(IsAuthenticatedMixin, View):
|
||||
class PlaceCreateView(IsAuthenticated, View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_image_form = PlaceImageCreateForm()
|
||||
@ -117,7 +117,7 @@ class PlaceCreateView(IsAuthenticatedMixin, View):
|
||||
)
|
||||
place_image.save()
|
||||
|
||||
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
|
||||
class PlaceDeleteView(IsAuthenticated, IsPlaceSubmitter, DeleteView):
|
||||
template_name = 'place/place_delete.html'
|
||||
model = 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.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 (
|
||||
PlaceAssetCreateView,
|
||||
@ -24,7 +24,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
|
||||
template_name = 'signup.html'
|
||||
success_message = 'User created.'
|
||||
|
||||
class HomeView(IsAuthenticatedMixin, View):
|
||||
class HomeView(IsAuthenticated, 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(IsAuthenticatedMixin, View):
|
||||
class PlaceTagSubmitView(IsAuthenticated, 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(IsAuthenticatedMixin, View):
|
||||
|
||||
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):
|
||||
place = Place.objects.get(pk=tagged_id)
|
||||
tag = Tag.objects.get(pk=tag_id)
|
||||
|
Loading…
Reference in New Issue
Block a user