#9 Using morge 404
This commit is contained in:
parent
00ab65d648
commit
2a3ee3de8d
@ -6,7 +6,7 @@ from django.contrib import messages
|
|||||||
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
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 django.urls import reverse_lazy
|
||||||
|
|
||||||
from lostplaces.models import Place
|
from lostplaces.models import Place
|
||||||
@ -62,11 +62,11 @@ class PlaceAssetCreateView(IsAuthenticatedMixin, SuccessMessageMixin, CreateView
|
|||||||
success_message = ''
|
success_message = ''
|
||||||
|
|
||||||
def get(self, request, place_id, *args, **kwargs):
|
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)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def post(self, request, place_id, *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)
|
response = super().post(request, *args, **kwargs)
|
||||||
self.object.place = self.place
|
self.object.place = self.place
|
||||||
self.object.submitted_by = request.user.explorer
|
self.object.submitted_by = request.user.explorer
|
||||||
|
@ -6,7 +6,7 @@ from django.views.generic import ListView
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
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 django.urls import reverse_lazy
|
||||||
|
|
||||||
from lostplaces.models import Place, PlaceImage
|
from lostplaces.models import Place, PlaceImage
|
||||||
@ -31,7 +31,7 @@ class PlaceListView(IsAuthenticatedMixin, ListView):
|
|||||||
|
|
||||||
class PlaceDetailView(IsAuthenticatedMixin, View):
|
class PlaceDetailView(IsAuthenticatedMixin, View):
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
place = Place.objects.get(pk=pk)
|
place = get_object_or_404(Place, pk=pk)
|
||||||
context = {
|
context = {
|
||||||
'place': place,
|
'place': place,
|
||||||
'mapping_config': {
|
'mapping_config': {
|
||||||
|
@ -57,7 +57,7 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView):
|
|||||||
|
|
||||||
class PlaceTagSubmitView(IsAuthenticatedMixin, View):
|
class PlaceTagSubmitView(IsAuthenticatedMixin, View):
|
||||||
def post(self, request, tagged_id, *args, **kwargs):
|
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)
|
form = TagSubmitForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
tag_list_raw = form.cleaned_data['tag_list']
|
tag_list_raw = form.cleaned_data['tag_list']
|
||||||
@ -72,8 +72,8 @@ class PlaceTagSubmitView(IsAuthenticatedMixin, View):
|
|||||||
|
|
||||||
class PlaceTagDeleteView(IsAuthenticatedMixin, View):
|
class PlaceTagDeleteView(IsAuthenticatedMixin, View):
|
||||||
def get(self, request, tagged_id, tag_id, *args, **kwargs):
|
def get(self, request, tagged_id, tag_id, *args, **kwargs):
|
||||||
place = Place.objects.get(pk=tagged_id)
|
place = get_object_or_404(Place, pk=tagged_id)
|
||||||
tag = Tag.objects.get(pk=tag_id)
|
tag = get_object_or_404(Tag, pk=tag_id)
|
||||||
place.tags.remove(tag)
|
place.tags.remove(tag)
|
||||||
return redirect(reverse_lazy('place_detail', kwargs={'pk': tagged_id}))
|
return redirect(reverse_lazy('place_detail', kwargs={'pk': tagged_id}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user