[PATCH] REST: allow fetching of subject prefixes (categories)

Daniel Axtens dja at axtens.net
Sat Feb 11 21:55:36 AEDT 2017


Some mailing lists accept patches for multiple projects, and use
a subject prefix to differentiate the projects.

Therefore, for snowpatch, it's useful to be able to fetch the
subject prefixes. Snowpatch calls these 'categories', so lets
adopt their terminology.

Export categeories in the REST API.

Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 patchwork/api/patch.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 1a7be584d0be..5536c41079b8 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -31,6 +31,7 @@ from patchwork.api.base import PatchworkPermission
 from patchwork.api.filters import PatchFilter
 from patchwork.models import Patch
 from patchwork.models import State
+from patchwork.parser import clean_subject
 
 
 def format_state_name(state):
@@ -76,6 +77,10 @@ class PatchListSerializer(HyperlinkedModelSerializer):
     tags = SerializerMethodField()
     check = SerializerMethodField()
     checks = SerializerMethodField()
+    categories = SerializerMethodField()
+
+    def get_categories(self, instance):
+        return clean_subject(instance.name)[1]
 
     def get_mbox(self, instance):
         request = self.context.get('request')
@@ -100,10 +105,10 @@ 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', 'categories')
         read_only_fields = ('project', 'msgid', 'date', 'name', 'hash',
                             'submitter', 'mbox', 'mbox', 'series', 'check',
-                            'checks', 'tags')
+                            'checks', 'tags', 'categories')
         extra_kwargs = {
             'url': {'view_name': 'api-patch-detail'},
             'project': {'view_name': 'api-project-detail'},
-- 
2.9.3



More information about the Patchwork mailing list