diff mbox series

REST: squish final open-codings of get_object_or_404

Message ID 20210823074700.2995270-1-dja@axtens.net
State Accepted
Headers show
Series REST: squish final open-codings of get_object_or_404 | expand

Commit Message

Daniel Axtens Aug. 23, 2021, 7:47 a.m. UTC
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 | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Daniel Axtens Aug. 23, 2021, 8:49 a.m. UTC | #1
Applied in order to apply Raxel's first 2 patches.

Daniel Axtens <dja@axtens.net> writes:

> 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 | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/patchwork/api/comment.py b/patchwork/api/comment.py
> index 0c578b44f1cb..e9c52b990080 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']
> -- 
> 2.30.2
diff mbox series

Patch

diff --git a/patchwork/api/comment.py b/patchwork/api/comment.py
index 0c578b44f1cb..e9c52b990080 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']