From: Daniel Axtens Date: Mon, 23 Aug 2021 07:29:53 +0000 (+1000) Subject: REST: squish final open-codings of get_object_or_404 X-Git-Tag: v3.1.0~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0ed2feb26c84;p=thirdparty%2Fpatchwork.git REST: squish final open-codings of get_object_or_404 Basically, finish the job of commit fecf7c86c2c5 ("urls: Add missing path converters for REST APIs"). With this commit, there are no more uses of Http404 in patchwork/api Signed-off-by: Daniel Axtens --- diff --git a/patchwork/api/comment.py b/patchwork/api/comment.py index 0c578b44..e9c52b99 100644 --- a/patchwork/api/comment.py +++ b/patchwork/api/comment.py @@ -5,7 +5,7 @@ import email.parser -from django.http import Http404 +from rest_framework.generics import get_object_or_404 from rest_framework.generics import ListAPIView from rest_framework.serializers import SerializerMethodField @@ -86,8 +86,7 @@ class CoverCommentList(ListAPIView): lookup_url_kwarg = 'pk' def get_queryset(self): - if not Cover.objects.filter(pk=self.kwargs['pk']).exists(): - raise Http404 + get_object_or_404(Cover, pk=self.kwargs['pk']) return CoverComment.objects.filter( cover=self.kwargs['pk'] @@ -105,8 +104,7 @@ class PatchCommentList(ListAPIView): lookup_url_kwarg = 'patch_id' def get_queryset(self): - if not Patch.objects.filter(id=self.kwargs['patch_id']).exists(): - raise Http404 + get_object_or_404(Patch, id=self.kwargs['patch_id']) return PatchComment.objects.filter( patch=self.kwargs['patch_id']