added logic to display ebooks, badly for now

pull/1/head
Ed Summers 2011-11-07 15:39:02 -05:00
parent 7753c49656
commit 110b996769
7 changed files with 103 additions and 53 deletions

View File

@ -160,6 +160,19 @@ class Work(models.Model):
status = percent;
return status;
def first_pdf(self):
return self.first_ebook('pdf')
def first_epub(self):
return self.first_ebook('epub')
def first_ebook(self, ebook_format=None):
for edition in self.editions.all():
for ebook in edition.ebooks.all():
if ebook_format == None or ebook.format == ebook_format:
return ebook
return None
def __unicode__(self):
return self.title

View File

@ -7,8 +7,6 @@ def gluejar_search(q):
results = []
for item in googlebooks_search(q)['items']:
# TODO: better to think in terms of editions with titles
# instead of titles with names?
v = item['volumeInfo']
r = {'title': v.get('title', ""),
'description': v.get('description', ""),
@ -36,6 +34,14 @@ def gluejar_search(q):
else:
r['image'] = ""
access_info = item.get('accessInfo')
if access_info:
epub = access_info.get('epub')
if epub and epub.get('downloadLink'):
r['epub'] = epub['downloadLink']
pdf = access_info.get('pdf')
if pdf and pdf.get('downloadLink'):
r['pdf'] = pdf['downloadLink']
results.append(r)
return results

View File

@ -121,6 +121,10 @@ class TestBookLoader(TestCase):
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')
w = edition.work
self.assertEqual(w.first_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(w.first_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")
def test_add_no_ebook(self):
# this edition lacks an ebook, but we should still be able to load it
e = bookloader.add_by_isbn('0465019358')

View File

@ -80,6 +80,18 @@ $(document).ready(function(){
<img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" />
</span>
</div>
<div class="listview ebooks">
{% if result.epub %}
<span class="boolist-ebook">
<a href="{{ result.epub }}">epub</a>
</span>
{% endif %}
{% if result.pdf %}
<span class="boolist-ebook">
<a href="{{ result.pdf }}">pdf</a>
</span>
{% endif %}
</div>
<div class="unglue-this none">
<div class="unglue-this-inner1">
<div class="unglue-this-inner2">

View File

@ -291,6 +291,18 @@ how do I integrate the your wishlist thing with the tabs thing?
<div class="booklist-status-label">100%</div>
<div class="right_add"><img src="/static/images/book-panel/add_gray.png" border="0" /></div>
</div>
<div class="listview ebooks">
{% if work.first_epub %}
<span class="boolist-ebook">
<a href="{{ work.first_epub.url }}">epub</a>
</span>
{% endif %}
{% if work.first_pdf %}
<span class="boolist-ebook">
<a href="{{ work.first_pdf.url }}">pdf</a>
</span>
{% endif %}
</div>
<div class="unglue-this none">
<div class="unglue-this-inner1">
<div class="unglue-this-inner2">

View File

@ -50,6 +50,9 @@ def work(request, work_id, action='display'):
if campaign:
q = Q(campaign=campaign) | Q(campaign__isnull=True)
premiums = models.Premium.objects.filter(q)
else:
premiums = None
if action == 'setup_campaign':
return render(request, 'setup_campaign.html', {'work': work})
else:

BIN
static/images/unglued.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B