Added LoginRequiredMixin to check for authenticated user.
This commit is contained in:
parent
d554355f9c
commit
c0191fc6c4
@ -8,7 +8,7 @@ from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from django.views import View
|
||||
from django.http import Http404
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
||||
|
||||
from .forms import (
|
||||
ExplorerCreationForm,
|
||||
@ -19,6 +19,10 @@ from .models import Place, PlaceImage, Voucher
|
||||
|
||||
# Create your views here.
|
||||
|
||||
# BaseView that checks if user is logged in
|
||||
class IsAuthenticated(LoginRequiredMixin, View):
|
||||
redirect_field_name = 'redirect_to'
|
||||
|
||||
class SignUpView(CreateView):
|
||||
form_class = ExplorerCreationForm
|
||||
success_url = reverse_lazy('login')
|
||||
@ -41,7 +45,7 @@ class HomeView(View):
|
||||
}
|
||||
return render(request, 'home.html', context)
|
||||
|
||||
class PlaceUpdateView(UpdateView):
|
||||
class PlaceUpdateView(IsAuthenticated, UpdateView):
|
||||
template_name = 'place/place_update.html'
|
||||
model = Place
|
||||
form_class = PlaceForm
|
||||
@ -49,7 +53,7 @@ class PlaceUpdateView(UpdateView):
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk})
|
||||
|
||||
class PlaceCreateView(View):
|
||||
class PlaceCreateView(IsAuthenticated, View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
place_image_form = PlaceImageCreateForm()
|
||||
@ -97,7 +101,7 @@ class PlaceCreateView(View):
|
||||
)
|
||||
place_image.save()
|
||||
|
||||
class PlaceDeleteView(UserPassesTestMixin, DeleteView):
|
||||
class PlaceDeleteView(IsAuthenticated, UserPassesTestMixin, DeleteView):
|
||||
template_name = 'place/place_delete.html'
|
||||
model = Place
|
||||
success_url = reverse_lazy('place_list')
|
||||
|
Loading…
Reference in New Issue
Block a user