[PATCHv2 07/10] REST: Add Patch.mbox_url
Andy Doan
andy.doan at linaro.org
Wed May 11 08:39:24 AEST 2016
Provide a URL to the raw patch. This removes previous functionality
added to create_model_serializer thats no longer needed.
Signed-off-by: Andy Doan <andy.doan at linaro.org>
---
patchwork/models.py | 4 ++++
patchwork/rest_serializers.py | 7 ++++++-
patchwork/tests/test_rest_api.py | 1 +
3 files changed, 11 insertions(+), 1 deletion(-)
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 b39c8f4..6760948 100644
--- a/patchwork/rest_serializers.py
+++ b/patchwork/rest_serializers.py
@@ -20,7 +20,8 @@
from patchwork.models import Check, Patch, Person, Project
from rest_framework.serializers import (
- CurrentUserDefault, ModelSerializer, HiddenField, PrimaryKeyRelatedField)
+ CurrentUserDefault, ModelSerializer, HiddenField, PrimaryKeyRelatedField,
+ SerializerMethodField)
class PersonSerializer(ModelSerializer):
@@ -38,6 +39,10 @@ class PatchSerializer(ModelSerializer):
model = Patch
read_only_fields = ('project', 'name', 'date', 'submitter', 'diff',
'content', 'hash', 'msgid')
+ mbox_url = SerializerMethodField()
+
+ def get_mbox_url(self, patch):
+ return patch.get_mbox_url()
class CurrentPatchDefault(object):
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index c81edca..780edd4 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -195,6 +195,7 @@ class TestPatchAPI(APITestCase):
self.assertEqual(patches[0].diff, resp.data['diff'])
self.assertEqual(patches[0].submitter.id, resp.data['submitter'])
self.assertEqual(patches[0].state.id, resp.data['state'])
+ self.assertEqual(patches[0].get_mbox_url(), resp.data['mbox_url'])
def test_anonymous_writes(self):
"""Ensure anonymous "write" operations are rejected."""
--
2.7.4
More information about the Patchwork
mailing list