Skip to content

Commit

Permalink
REST: Expose cover mbox link via REST API
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed May 30, 2017
1 parent 5b716d4 commit 5cbcd3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion patchwork/api/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@ class CoverLetterListSerializer(HyperlinkedModelSerializer):

project = ProjectSerializer(read_only=True)
submitter = PersonSerializer(read_only=True)
mbox = SerializerMethodField()
series = SeriesSerializer(many=True, read_only=True)

def get_mbox(self, instance):
request = self.context.get('request')
return request.build_absolute_uri(instance.get_mbox_url())

class Meta:
model = CoverLetter
fields = ('id', 'url', 'project', 'msgid', 'date', 'name', 'submitter',
'series')
'mbox', 'series')
read_only_fields = fields
extra_kwargs = {
'url': {'view_name': 'api-cover-detail'},
}


class CoverLetterDetailSerializer(CoverLetterListSerializer):

headers = SerializerMethodField()

def get_headers(self, instance):
Expand Down
1 change: 1 addition & 0 deletions patchwork/tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def api_url(item=None):
def assertSerialized(self, cover_obj, cover_json):
self.assertEqual(cover_obj.id, cover_json['id'])
self.assertEqual(cover_obj.name, cover_json['name'])
self.assertIn(cover_obj.get_mbox_url(), cover_json['mbox'])

# nested fields

Expand Down

0 comments on commit 5cbcd3a

Please sign in to comment.