]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Add Patch.mbox_url
authorAndy Doan <andy.doan@linaro.org>
Thu, 16 Jun 2016 21:13:23 +0000 (16:13 -0500)
committerStephen Finucane <stephen.finucane@intel.com>
Mon, 27 Jun 2016 17:20:36 +0000 (18:20 +0100)
Provide a URL to the raw patch.

Signed-off-by: Andy Doan <andy.doan@linaro.org>
Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>
patchwork/models.py
patchwork/rest_serializers.py
patchwork/tests/test_rest_api.py

index 632427317785fb13f4147e7354cc9b16558d2eb7..6209527d0bb7d4f4f0f55a513301e223cae9b06d 100644 (file)
@@ -458,6 +458,10 @@ class Patch(Submission):
     def get_absolute_url(self):
         return ('patch-detail', (), {'patch_id': self.id})
 
+    @models.permalink
+    def get_mbox_url(self):
+        return ('patch-mbox', (), {'patch_id': self.id})
+
     def __str__(self):
         return self.name
 
index 552f84d3bbbf39c6f6efb5cf8a125a36d5295eef..688d8af5107dde61d5d8762b0c38d12c409338af 100644 (file)
@@ -85,11 +85,16 @@ class PatchSerializer(URLSerializer):
         # there's no need to expose an entire "tags" endpoint, so we custom
         # render this field
         exclude = ('tags',)
+    mbox_url = SerializerMethodField()
     state = SerializerMethodField()
 
     def get_state(self, obj):
         return obj.state.name
 
+    def get_mbox_url(self, patch):
+        request = self.context.get('request', None)
+        return request.build_absolute_uri(patch.get_mbox_url())
+
     def to_representation(self, instance):
         data = super(PatchSerializer, self).to_representation(instance)
         data['checks_url'] = data['url'] + 'checks/'
index 837007d693efaa59abffa8b8fca109d933f2d4d4..4f5886f7f034a53173bfedc8b4ca4755e4984e37 100644 (file)
@@ -260,6 +260,7 @@ class TestPatchAPI(APITestCase):
         self.assertIn(TestPersonAPI.api_url(self.patches[0].submitter.id),
                       resp.data['submitter_url'])
         self.assertEqual(self.patches[0].state.name, resp.data['state'])
+        self.assertIn(self.patches[0].get_mbox_url(), resp.data['mbox_url'])
 
     def test_detail_tags(self):
         # defaults.project is remembered between TestCases and .save() is