[09/11] REST: Expose Patch.labels

Message ID 20180415225405.1354-10-stephen@that.guru
State Superseded
Headers show
Series
  • Add labels support
Related show

Commit Message

Stephen Finucane April 15, 2018, 10:54 p.m.
This closes out the labels feature.

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

Patch

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')