Handle empty edition_id

This commit is contained in:
Lukáš Kucharczyk 2023-11-17 09:08:30 +01:00
parent 0f5067d66d
commit 583efe1754
1 changed files with 9 additions and 2 deletions

View File

@ -1,13 +1,18 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Any, Callable from typing import Any, Callable
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Count, F, Prefetch, Sum from django.db.models import Count, F, Prefetch, Sum
from django.db.models.functions import TruncDate 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.shortcuts import redirect, render
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.core.exceptions import ObjectDoesNotExist
from common.time import format_duration from common.time import format_duration
from common.utils import safe_division from common.utils import safe_division
@ -212,6 +217,8 @@ def edit_edition(request, edition_id=None):
def related_purchase_by_edition(request): def related_purchase_by_edition(request):
edition_id = request.GET.get("edition") edition_id = request.GET.get("edition")
if not edition_id:
return HttpResponseBadRequest("Invalid edition_id")
form = PurchaseForm() form = PurchaseForm()
form.fields["related_purchase"].queryset = Purchase.objects.filter( form.fields["related_purchase"].queryset = Purchase.objects.filter(
edition_id=edition_id, type=Purchase.GAME edition_id=edition_id, type=Purchase.GAME