@@ -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
@@ -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/'
@@ -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()