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:
parent
6d06aa4ef5
commit
7d24d56493
@ -84,12 +84,9 @@ class DocumentMetaField(MetaField):
|
|||||||
data = OrderedDict([
|
data = OrderedDict([
|
||||||
('type', "wagtaildocs.Document"),
|
('type', "wagtaildocs.Document"),
|
||||||
('detail_url', get_object_detail_url(self.context, type(document), document.pk)),
|
('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
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class TestDocumentListing(TestCase):
|
|||||||
for document in content['documents']:
|
for document in content['documents']:
|
||||||
self.assertIn('meta', document)
|
self.assertIn('meta', document)
|
||||||
self.assertIsInstance(document['meta'], dict)
|
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
|
# Type should always be wagtaildocs.Document
|
||||||
self.assertEqual(document['meta']['type'], 'wagtaildocs.Document')
|
self.assertEqual(document['meta']['type'], 'wagtaildocs.Document')
|
||||||
@ -56,6 +56,9 @@ class TestDocumentListing(TestCase):
|
|||||||
# Check detail_url
|
# Check detail_url
|
||||||
self.assertEqual(document['meta']['detail_url'], 'http://localhost/api/v2beta/documents/%d/' % document['id'])
|
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
|
# EXTRA FIELDS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user