diff mbox

[PATCHv2,07/10] REST: Add Patch.mbox_url

Message ID 1462919967-26088-8-git-send-email-andy.doan@linaro.org
State Superseded
Headers show

Commit Message

Andy Doan May 10, 2016, 10:39 p.m. UTC
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@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(-)

Comments

Stephen Finucane May 17, 2016, 1:16 p.m. UTC | #1
On 10 May 17:39, Andy Doan wrote:
> Provide a URL to the raw patch. This removes previous functionality
> added to create_model_serializer thats no longer needed.

What functionality is removed? Are you referencing the previous patch?
If so, don't bother :)

> Signed-off-by: Andy Doan <andy.doan@linaro.org>

Short and sweet.

Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>
diff mbox

Patch

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."""