Intercept bad uuids

This commit is contained in:
2022-04-19 19:25:36 +02:00
parent b88faf931c
commit 1cd6f1107c

View File

@@ -5,6 +5,7 @@ from django.views import View
from django.http import Http404 from django.http import Http404
from django.db.models import Q from django.db.models import Q
from django.shortcuts import render from django.shortcuts import render
from django.core.exceptions import ObjectDoesNotExist
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from portal.utils import get_site_conf from portal.utils import get_site_conf
@@ -96,7 +97,10 @@ class GetHomeFiltered(View):
class GetRollingStock(View): class GetRollingStock(View):
def get(self, request, uuid): def get(self, request, uuid):
try:
rolling_stock = RollingStock.objects.get(uuid=uuid) rolling_stock = RollingStock.objects.get(uuid=uuid)
except ObjectDoesNotExist:
raise Http404
return render( return render(
request, request,
@@ -126,7 +130,10 @@ class Consists(View):
class GetConsist(View): class GetConsist(View):
def get(self, request, uuid, page=1): def get(self, request, uuid, page=1):
site_conf = get_site_conf() site_conf = get_site_conf()
try:
consist = Consist.objects.get(uuid=uuid) consist = Consist.objects.get(uuid=uuid)
except ObjectDoesNotExist:
raise Http404
rolling_stock = consist.consist_item.all() rolling_stock = consist.consist_item.all()
paginator = Paginator(rolling_stock, site_conf.items_per_page) paginator = Paginator(rolling_stock, site_conf.items_per_page)