#9 Using morge 404

This commit is contained in:
reverend 2020-09-18 23:32:52 +02:00
parent 00ab65d648
commit 2a3ee3de8d
3 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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': {

View File

@ -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}))