diff --git a/core/bookloader.py b/core/bookloader.py index 8473c5b2..ed2993d7 100755 --- a/core/bookloader.py +++ b/core/bookloader.py @@ -103,10 +103,17 @@ def add_by_googlebooks_id(googlebooks_id, work=None): e.public_domain = item.get('public_domain', None) epub = access_info.get('epub') if epub and epub.get('downloadLink'): - ebook = models.Ebook(edition=e, + ebook = models.Ebook(edition=e, format='epub', url=epub.get('downloadLink'), provider='google') ebook.save() + + pdf = access_info.get('pdf') + if pdf and pdf.get('downloadLink'): + ebook = models.Ebook(edition=e, format='pdf', + url=pdf.get('downloadLink', None), + provider='google') + ebook.save() # if we know what work to add the edition to do it if work: diff --git a/core/tests.py b/core/tests.py index d76433c9..af5ace3f 100755 --- a/core/tests.py +++ b/core/tests.py @@ -110,10 +110,16 @@ class TestBookLoader(TestCase): def test_ebook(self): edition = bookloader.add_by_oclc('1246014') - self.assertEqual(edition.ebooks.count(), 1) - ebook = edition.ebooks.all()[0] - self.assertEqual(ebook.url, 'http://books.google.com/books/download/The_Latin_language.epub?id=U3FXAAAAYAAJ&ie=ISO-8859-1&output=epub&source=gbs_api') - self.assertEqual(ebook.provider, 'google') + self.assertEqual(edition.ebooks.count(), 2) + #ebook_epub = edition.ebooks.all()[0] + ebook_epub = edition.ebooks.filter(format='epub')[0] + self.assertEqual(ebook_epub.format, 'epub') + self.assertEqual(ebook_epub.url, 'http://books.google.com/books/download/The_Latin_language.epub?id=U3FXAAAAYAAJ&ie=ISO-8859-1&output=epub&source=gbs_api') + self.assertEqual(ebook_epub.provider, 'google') + ebook_pdf = edition.ebooks.filter(format='pdf')[0] + self.assertEqual(ebook_pdf.format, 'pdf') + self.assertEqual(ebook_pdf.url, 'http://books.google.com/books/download/The_Latin_language.pdf?id=U3FXAAAAYAAJ&ie=ISO-8859-1&output=pdf&sig=ACfU3U2yLt3nmTncB8ozxOWUc4iHKUznCA&source=gbs_api') + self.assertEqual(ebook_pdf.provider, 'google') def test_add_no_ebook(self): # this edition lacks an ebook, but we should still be able to load it