[PATCH v5 08/10] REST: Add Patch.mbox_url
Andy Doan
andy.doan at linaro.org
Fri May 27 11:12:44 AEST 2016
Provide a URL to the raw patch.
Signed-off-by: Andy Doan <andy.doan at linaro.org>
Reviewed-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/models.py | 4 ++++
patchwork/rest_serializers.py | 5 +++++
patchwork/tests/test_rest_api.py | 1 +
3 files changed, 10 insertions(+)
diff --git a/patchwork/models.py b/patchwork/models.py
index 6324273..6209527 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -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
diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py
index f3cca50..710d714 100644
--- a/patchwork/rest_serializers.py
+++ b/patchwork/rest_serializers.py
@@ -70,11 +70,16 @@ class PatchSerializer(HyperlinkedModelSerializer):
# 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'] = data['url'] + 'checks/'
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 4ef4646..0911318 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -264,6 +264,7 @@ class TestPatchAPI(APITestCase):
self.assertIn(TestPersonAPI.api_url(patches[0].submitter.id),
resp.data['submitter'])
self.assertEqual(patches[0].state.name, resp.data['state'])
+ self.assertIn(patches[0].get_mbox_url(), resp.data['mbox_url'])
def test_detail_tags(self):
patches = create_patches()
--
2.7.4
More information about the Patchwork
mailing list