From 91c888db8ff6275f35c315f76f666840b58e9b45 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 2 Sep 2020 00:22:42 +0200 Subject: [PATCH] Handle HomeView for unauthenticated users with separate template. --- lostplaces/lostplaces_app/views/views.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lostplaces/lostplaces_app/views/views.py b/lostplaces/lostplaces_app/views/views.py index 28f7f25..552ca7a 100644 --- a/lostplaces/lostplaces_app/views/views.py +++ b/lostplaces/lostplaces_app/views/views.py @@ -8,6 +8,7 @@ from django.shortcuts import render, redirect from lostplaces_app.forms import ExplorerCreationForm from lostplaces_app.models import Place, PhotoAlbum +from lostplaces_app.views import IsAuthenticated from lostplaces_app.views.base_views import ( PlaceAssetCreateView, @@ -19,7 +20,7 @@ class SignUpView(SuccessMessageMixin, CreateView): template_name = 'signup.html' success_message = 'User created.' -class HomeView(View): +class HomeView(IsAuthenticated, View): def get(self, request, *args, **kwargs): place_list = Place.objects.all().order_by('-submitted_when')[:10] place_map_center = Place.average_latlon(place_list) @@ -29,6 +30,13 @@ class HomeView(View): } return render(request, 'home.html', context) + def handle_no_permission(self): + place_list = Place.objects.all().order_by('-submitted_when')[:10] + context = { + 'place_list': place_list + } + return render(self.request, 'home_unauth.html', context) + class PhotoAlbumCreateView(PlaceAssetCreateView): model = PhotoAlbum fields = ['url', 'label']