[PATCH] REST: Show 'comments' in '/patches', '/comments'

Stephen Finucane stephen at that.guru
Sat Apr 28 01:35:06 AEST 2018


This link is only shown for individual resources at the moment. Modify
this behavior.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Cc: Veronika Kabatova <vkabatov at redhat.com>
---
 patchwork/api/cover.py | 20 +++++++++-----------
 patchwork/api/patch.py | 37 +++++++++++++++++++------------------
 2 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 01c9fbb6..7c80064c 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -38,18 +38,23 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer):
     submitter = PersonSerializer(read_only=True)
     mbox = SerializerMethodField()
     series = SeriesSerializer(many=True, read_only=True)
+    comments = SerializerMethodField()
 
     def get_mbox(self, instance):
         request = self.context.get('request')
         return request.build_absolute_uri(instance.get_mbox_url())
 
+    def get_comments(self, cover):
+        return self.context.get('request').build_absolute_uri(
+            reverse('api-comment-list', kwargs={'pk': cover.id}))
+
     class Meta:
         model = CoverLetter
         fields = ('id', 'url', 'project', 'msgid', 'date', 'name', 'submitter',
-                  'mbox', 'series')
+                  'mbox', 'series', 'comments')
         read_only_fields = fields
         versioned_fields = {
-            '1.1': ('mbox', ),
+            '1.1': ('mbox', 'comments'),
         }
         extra_kwargs = {
             'url': {'view_name': 'api-cover-detail'},
@@ -59,11 +64,6 @@ class CoverLetterListSerializer(BaseHyperlinkedModelSerializer):
 class CoverLetterDetailSerializer(CoverLetterListSerializer):
 
     headers = SerializerMethodField()
-    comments = SerializerMethodField()
-
-    def get_comments(self, cover):
-        return self.context.get('request').build_absolute_uri(
-            reverse('api-comment-list', kwargs={'pk': cover.id}))
 
     def get_headers(self, instance):
         headers = {}
@@ -82,12 +82,10 @@ class CoverLetterDetailSerializer(CoverLetterListSerializer):
     class Meta:
         model = CoverLetter
         fields = CoverLetterListSerializer.Meta.fields + (
-            'headers', 'content', 'comments')
+            'headers', 'content')
         read_only_fields = fields
         extra_kwargs = CoverLetterListSerializer.Meta.extra_kwargs
-        versioned_fields = {
-            '1.1': ('mbox', 'comments'),
-        }
+        versioned_fields = CoverLetterListSerializer.Meta.versioned_fields
 
 
 class CoverLetterList(ListAPIView):
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 8aca8915..d1931c01 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -83,6 +83,7 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
     delegate = UserSerializer()
     mbox = SerializerMethodField()
     series = SeriesSerializer(many=True, read_only=True)
+    comments = SerializerMethodField()
     check = SerializerMethodField()
     checks = SerializerMethodField()
     tags = SerializerMethodField()
@@ -91,10 +92,9 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
         request = self.context.get('request')
         return request.build_absolute_uri(instance.get_mbox_url())
 
-    def get_tags(self, instance):
-        # TODO(stephenfin): Make tags performant, possibly by reworking the
-        # model
-        return {}
+    def get_comments(self, patch):
+        return self.context.get('request').build_absolute_uri(
+            reverse('api-comment-list', kwargs={'pk': patch.id}))
 
     def get_check(self, instance):
         return instance.combined_check_state
@@ -103,15 +103,23 @@ class PatchListSerializer(BaseHyperlinkedModelSerializer):
         return self.context.get('request').build_absolute_uri(
             reverse('api-check-list', kwargs={'patch_id': instance.id}))
 
+    def get_tags(self, instance):
+        # TODO(stephenfin): Make tags performant, possibly by reworking the
+        # model
+        return {}
+
     class Meta:
         model = Patch
         fields = ('id', 'url', 'project', 'msgid', 'date', 'name',
                   'commit_ref', 'pull_url', 'state', 'archived', 'hash',
-                  'submitter', 'delegate', 'mbox', 'series', 'check', 'checks',
-                  'tags')
+                  'submitter', 'delegate', 'mbox', 'series', 'comments',
+                  'check', 'checks', 'tags')
         read_only_fields = ('project', 'msgid', 'date', 'name', 'hash',
-                            'submitter', 'mbox', 'mbox', 'series', 'check',
-                            'checks', 'tags')
+                            'submitter', 'mbox', 'mbox', 'series', 'comments',
+                            'check', 'checks', 'tags')
+        versioned_fields = {
+            '1.1': ('comments', ),
+        }
         extra_kwargs = {
             'url': {'view_name': 'api-patch-detail'},
         }
@@ -121,11 +129,6 @@ class PatchDetailSerializer(PatchListSerializer):
 
     headers = SerializerMethodField()
     prefixes = SerializerMethodField()
-    comments = SerializerMethodField()
-
-    def get_comments(self, patch):
-        return self.context.get('request').build_absolute_uri(
-            reverse('api-comment-list', kwargs={'pk': patch.id}))
 
     def get_headers(self, patch):
         headers = {}
@@ -147,13 +150,11 @@ class PatchDetailSerializer(PatchListSerializer):
     class Meta:
         model = Patch
         fields = PatchListSerializer.Meta.fields + (
-            'headers', 'content', 'diff', 'prefixes', 'comments')
+            'headers', 'content', 'diff', 'prefixes')
         read_only_fields = PatchListSerializer.Meta.read_only_fields + (
-            'headers', 'content', 'diff', 'prefixes', 'comments')
+            'headers', 'content', 'diff', 'prefixes')
+        versioned_fields = PatchListSerializer.Meta.versioned_fields
         extra_kwargs = PatchListSerializer.Meta.extra_kwargs
-        versioned_fields = {
-            '1.1': ('comments', ),
-        }
 
 
 class PatchList(ListAPIView):
-- 
2.14.3



More information about the Patchwork mailing list