]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: squish final open-codings of get_object_or_404
authorDaniel Axtens <dja@axtens.net>
Mon, 23 Aug 2021 07:29:53 +0000 (17:29 +1000)
committerDaniel Axtens <dja@axtens.net>
Mon, 23 Aug 2021 07:46:29 +0000 (17:46 +1000)
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 <dja@axtens.net>
patchwork/api/comment.py

index 0c578b44f1cb6ec84c2ee1a54b7f1d347e741e45..e9c52b99008040ec190573c0cd12c830be7c1aaa 100644 (file)
@@ -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']