From 2a3ee3de8d4d765c7cf549e117333a6636460d5b Mon Sep 17 00:00:00 2001 From: reverend Date: Fri, 18 Sep 2020 23:32:52 +0200 Subject: [PATCH] #9 Using morge 404 --- django_lostplaces/lostplaces/views/base_views.py | 6 +++--- django_lostplaces/lostplaces/views/place_views.py | 4 ++-- django_lostplaces/lostplaces/views/views.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/django_lostplaces/lostplaces/views/base_views.py b/django_lostplaces/lostplaces/views/base_views.py index 7ee23b5..6717ede 100644 --- a/django_lostplaces/lostplaces/views/base_views.py +++ b/django_lostplaces/lostplaces/views/base_views.py @@ -6,7 +6,7 @@ from django.contrib import messages from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin from django.contrib.messages.views import SuccessMessageMixin -from django.shortcuts import redirect +from django.shortcuts import redirect, get_object_or_404 from django.urls import reverse_lazy from lostplaces.models import Place @@ -62,11 +62,11 @@ class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView success_message = '' def get(self, request, place_id, *args, **kwargs): - self.place = Place.objects.get(pk=place_id) + self.place = get_object_or_404(Place, pk=place_id) return super().get(request, *args, **kwargs) def post(self, request, place_id, *args, **kwargs): - self.place = Place.objects.get(pk=place_id) + self.place = get_object_or_404(Place, pk=place_id) response = super().post(request, *args, **kwargs) self.object.place = self.place self.object.submitted_by = request.user.explorer diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 9ff709a..8809767 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -6,7 +6,7 @@ from django.views.generic import ListView from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy from lostplaces.models import Place, PlaceImage @@ -31,7 +31,7 @@ class PlaceListView(IsAuthenticatedMixin, ListView): class PlaceDetailView(IsAuthenticatedMixin, View): def get(self, request, pk): - place = Place.objects.get(pk=pk) + place = get_object_or_404(Place, pk=pk) context = { 'place': place, 'mapping_config': { diff --git a/django_lostplaces/lostplaces/views/views.py b/django_lostplaces/lostplaces/views/views.py index d50aabd..7fbb9d9 100644 --- a/django_lostplaces/lostplaces/views/views.py +++ b/django_lostplaces/lostplaces/views/views.py @@ -57,7 +57,7 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView): class PlaceTagSubmitView(IsAuthenticatedMixin, View): def post(self, request, tagged_id, *args, **kwargs): - place = Place.objects.get(pk=tagged_id) + place = get_object_or_404(Place, pk=tagged_id) form = TagSubmitForm(request.POST) if form.is_valid(): tag_list_raw = form.cleaned_data['tag_list'] @@ -72,8 +72,8 @@ class PlaceTagSubmitView(IsAuthenticatedMixin, View): class PlaceTagDeleteView(IsAuthenticatedMixin, 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) + place = get_object_or_404(Place, pk=tagged_id) + tag = get_object_or_404(Tag, pk=tag_id) place.tags.remove(tag) return redirect(reverse_lazy('place_detail', kwargs={'pk': tagged_id}))