[PATCH 09/11] REST: Expose Patch.labels

Stephen Finucane stephen at that.guru
Mon Apr 16 08:54:03 AEST 2018


This closes out the labels feature.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Fixes: #22
---
 patchwork/api/patch.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 115feffa..47929d64 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -108,10 +108,13 @@ class PatchListSerializer(HyperlinkedModelSerializer):
         fields = ('id', 'url', 'project', 'msgid', 'date', 'name',
                   'commit_ref', 'pull_url', 'state', 'archived', 'hash',
                   'submitter', 'delegate', 'mbox', 'series', 'check', 'checks',
-                  'tags')
+                  'tags', 'labels')
         read_only_fields = ('project', 'msgid', 'date', 'name', 'hash',
                             'submitter', 'mbox', 'mbox', 'series', 'check',
-                            'checks', 'tags')
+                            'checks', 'tags', 'labels')
+        versioned_fields = {
+            '1.1': ('labels',),
+        }
         extra_kwargs = {
             'url': {'view_name': 'api-patch-detail'},
         }
@@ -135,6 +138,7 @@ class PatchDetailSerializer(PatchListSerializer):
             'headers', 'content', 'diff', 'prefixes')
         read_only_fields = PatchListSerializer.Meta.read_only_fields + (
             'headers', 'content', 'diff', 'prefixes')
+        versioned_fields = PatchListSerializer.Meta.versioned_fields
         extra_kwargs = PatchListSerializer.Meta.extra_kwargs
 
 
@@ -151,7 +155,7 @@ class PatchList(ListAPIView):
 
     def get_queryset(self):
         return Patch.objects.all()\
-            .prefetch_related('series', 'check_set')\
+            .prefetch_related('series', 'labels', 'check_set')\
             .select_related('project', 'state', 'submitter', 'delegate')\
             .defer('content', 'diff', 'headers')
 
@@ -164,5 +168,5 @@ class PatchDetail(RetrieveUpdateAPIView):
 
     def get_queryset(self):
         return Patch.objects.all()\
-            .prefetch_related('series', 'check_set')\
+            .prefetch_related('series', 'labels', 'check_set')\
             .select_related('project', 'state', 'submitter', 'delegate')
-- 
2.14.3



More information about the Patchwork mailing list