From 7d24d564938d16b4939688c82b670359ce744b8f Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Thu, 8 Oct 2015 20:55:05 +0100 Subject: [PATCH] feat(api/2): Make document download_url available in listings --- wagtail/api/v2/serializers.py | 5 +---- wagtail/api/v2/tests/test_documents.py | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wagtail/api/v2/serializers.py b/wagtail/api/v2/serializers.py index 134fa961a7..4370c4cde1 100644 --- a/wagtail/api/v2/serializers.py +++ b/wagtail/api/v2/serializers.py @@ -84,12 +84,9 @@ class DocumentMetaField(MetaField): data = OrderedDict([ ('type', "wagtaildocs.Document"), ('detail_url', get_object_detail_url(self.context, type(document), document.pk)), + ('download_url', get_full_url(self.context['request'], document.url)), ]) - # Add download url - if self.context.get('show_details', False): - data['download_url'] = get_full_url(self.context['request'], document.url) - return data diff --git a/wagtail/api/v2/tests/test_documents.py b/wagtail/api/v2/tests/test_documents.py index b0dc682965..cafc9b6bd6 100644 --- a/wagtail/api/v2/tests/test_documents.py +++ b/wagtail/api/v2/tests/test_documents.py @@ -48,7 +48,7 @@ class TestDocumentListing(TestCase): for document in content['documents']: self.assertIn('meta', document) self.assertIsInstance(document['meta'], dict) - self.assertEqual(set(document['meta'].keys()), {'type', 'detail_url'}) + self.assertEqual(set(document['meta'].keys()), {'type', 'detail_url', 'download_url'}) # Type should always be wagtaildocs.Document self.assertEqual(document['meta']['type'], 'wagtaildocs.Document') @@ -56,6 +56,9 @@ class TestDocumentListing(TestCase): # Check detail_url self.assertEqual(document['meta']['detail_url'], 'http://localhost/api/v2beta/documents/%d/' % document['id']) + # Check download_url + self.assertTrue(document['meta']['download_url'].startswith('http://localhost/documents/%d/' % document['id'])) + # EXTRA FIELDS