0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

feat(api/2): Make document download_url available in listings

This commit is contained in:
Karl Hobley 2015-10-08 20:55:05 +01:00
parent 6d06aa4ef5
commit 7d24d56493
2 changed files with 5 additions and 5 deletions

View File

@ -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

View File

@ -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