Merge pull request #447 from mouse-reeve/editions-page

Editions page
This commit is contained in:
Mouse Reeve 2020-12-31 08:06:20 -08:00 committed by GitHub
commit 048db1a6bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -126,6 +126,14 @@ class Work(OrderedCollectionPageMixin, Book):
''' in case the default edition is not set ''' ''' in case the default edition is not set '''
return self.default_edition or self.editions.first() return self.default_edition or self.editions.first()
def to_edition_list(self, **kwargs):
''' an ordered collection of editions '''
return self.to_ordered_collection(
self.editions.all(),
remote_id='%s/editions' % self.remote_id,
**kwargs
)
activity_serializer = activitypub.Work activity_serializer = activitypub.Work
serialize_reverse_fields = [('editions', 'editions')] serialize_reverse_fields = [('editions', 'editions')]
deserialize_reverse_fields = [('editions', 'editions')] deserialize_reverse_fields = [('editions', 'editions')]

View file

@ -17,7 +17,9 @@ class Views(TestCase):
def setUp(self): def setUp(self):
''' we need basic test data and mocks ''' ''' we need basic test data and mocks '''
self.factory = RequestFactory() self.factory = RequestFactory()
self.book = models.Edition.objects.create(title='Test Book') self.work = models.Work.objects.create(title='Test Work')
self.book = models.Edition.objects.create(
title='Test Book', parent_work=self.work)
models.Connector.objects.create( models.Connector.objects.create(
identifier='self', identifier='self',
connector_file='self_connector', connector_file='self_connector',
@ -176,3 +178,21 @@ class Views(TestCase):
self.assertEqual(response.template_name, 'search_results.html') self.assertEqual(response.template_name, 'search_results.html')
self.assertEqual( self.assertEqual(
response.context_data['book_results'][0].title, 'Gideon the Ninth') response.context_data['book_results'][0].title, 'Gideon the Ninth')
def test_editions_page(self):
''' there are so many views, this just makes sure it LOADS '''
request = self.factory.get('')
with patch('bookwyrm.views.is_api_request') as is_api:
is_api.return_value = False
result = views.editions_page(request, self.work.id)
self.assertIsInstance(result, TemplateResponse)
self.assertEqual(result.template_name, 'editions.html')
self.assertEqual(result.status_code, 200)
request = self.factory.get('')
with patch('bookwyrm.views.is_api_request') as is_api:
is_api.return_value = True
result = views.editions_page(request, self.work.id)
self.assertIsInstance(result, JsonResponse)
self.assertEqual(result.status_code, 200)