[PATCH 3/6] REST: Embed 'mbox' parameter in /series

Stephen Finucane stephen at that.guru
Tue May 16 09:14:32 AEST 2017


This wasn't added in '6deedfb7' but it should have been.

Signed-off-by: Stephen Finucane <stephen at that.guru>
Fixes: 6deedfb7 ("views: Expose Series mbox")
---
 patchwork/api/series.py          | 11 +++++++++--
 patchwork/models.py              |  4 ++++
 patchwork/tests/test_rest_api.py |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/patchwork/api/series.py b/patchwork/api/series.py
index 3d5847b..01f1cbb 100644
--- a/patchwork/api/series.py
+++ b/patchwork/api/series.py
@@ -20,6 +20,7 @@
 from rest_framework.generics import ListAPIView
 from rest_framework.generics import RetrieveAPIView
 from rest_framework.serializers import HyperlinkedModelSerializer
+from rest_framework.serializers import SerializerMethodField
 
 from patchwork.api.base import PatchworkPermission
 from patchwork.api.filters import SeriesFilter
@@ -28,13 +29,19 @@ from patchwork.models import Series
 
 class SeriesSerializer(HyperlinkedModelSerializer):
 
+    mbox = SerializerMethodField()
+
+    def get_mbox(self, instance):
+        request = self.context.get('request')
+        return request.build_absolute_uri(instance.get_mbox_url())
+
     class Meta:
         model = Series
         fields = ('id', 'url', 'project', 'name', 'date', 'submitter',
                   'version', 'total', 'received_total', 'received_all',
-                  'cover_letter', 'patches')
+                  'mbox', 'cover_letter', 'patches')
         read_only_fields = ('date', 'submitter', 'total', 'received_total',
-                            'received_all', 'cover_letter', 'patches')
+                            'received_all', 'mbox', 'cover_letter', 'patches')
         extra_kwargs = {
             'url': {'view_name': 'api-series-detail'},
             'project': {'view_name': 'api-project-detail'},
diff --git a/patchwork/models.py b/patchwork/models.py
index 495bbcd..8913fac 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -658,6 +658,10 @@ class Series(models.Model):
                                           patch=patch,
                                           number=number)
 
+    @models.permalink
+    def get_mbox_url(self):
+        return ('series-mbox', (), {'series_id': self.id})
+
     def __str__(self):
         return self.name if self.name else 'Untitled series #%d' % self.id
 
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 236b3dc..4dcfb3a 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -511,6 +511,7 @@ class TestSeriesAPI(APITestCase):
     def assertSerialized(self, series_obj, series_json):
         self.assertEqual(series_obj.id, series_json['id'])
         self.assertEqual(series_obj.name, series_json['name'])
+        self.assertIn(series_obj.get_mbox_url(), series_json['mbox'])
         self.assertIn(TestProjectAPI.api_url(series_obj.project.id),
                       series_json['project'])
         self.assertIn(TestPersonAPI.api_url(series_obj.submitter.id),
-- 
2.9.3



More information about the Patchwork mailing list