From 583efe17541ec25736d6473401dda5a04f17bb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 17 Nov 2023 09:08:30 +0100 Subject: [PATCH] Handle empty edition_id --- games/views.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/games/views.py b/games/views.py index 3054321..092e480 100644 --- a/games/views.py +++ b/games/views.py @@ -1,13 +1,18 @@ from datetime import datetime, timedelta from typing import Any, Callable +from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, F, Prefetch, Sum from django.db.models.functions import TruncDate -from django.http import HttpRequest, HttpResponse, HttpResponseRedirect +from django.http import ( + HttpRequest, + HttpResponse, + HttpResponseBadRequest, + HttpResponseRedirect, +) from django.shortcuts import redirect, render from django.urls import reverse from django.utils import timezone -from django.core.exceptions import ObjectDoesNotExist from common.time import format_duration from common.utils import safe_division @@ -212,6 +217,8 @@ def edit_edition(request, edition_id=None): def related_purchase_by_edition(request): edition_id = request.GET.get("edition") + if not edition_id: + return HttpResponseBadRequest("Invalid edition_id") form = PurchaseForm() form.fields["related_purchase"].queryset = Purchase.objects.filter( edition_id=edition_id, type=Purchase.GAME