From 110b996769ca5d02d2dfd89428e030d4a501c311 Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Mon, 7 Nov 2011 15:39:02 -0500 Subject: [PATCH] added logic to display ebooks, badly for now --- core/models.py | 35 +++++++++----- core/search.py | 10 +++- core/tests.py | 4 ++ frontend/templates/search.html | 28 +++++++---- frontend/templates/supporter.html | 76 +++++++++++++++++------------- frontend/views.py | 3 ++ static/images/unglued.png | Bin 0 -> 526 bytes 7 files changed, 103 insertions(+), 53 deletions(-) create mode 100644 static/images/unglued.png diff --git a/core/models.py b/core/models.py index e0722262..21095319 100755 --- a/core/models.py +++ b/core/models.py @@ -103,8 +103,8 @@ class Campaign(models.Model): return self def supporters(self): - translist = self.transactions().values_list('user', flat=True).distinct() - return translist + translist = self.transactions().values_list('user', flat=True).distinct() + return translist class Work(models.Model): created = models.DateTimeField(auto_now_add=True) @@ -118,15 +118,15 @@ class Work(models.Model): return self.editions.all()[0].cover_image_thumbnail() def author(self): - authorlist = self.editions.all()[0].authors.all() - if authorlist.count() == 1: - myauthor = authorlist[0].name - elif authorlist.count() > 1: - myauthor = authorlist[0].name + ' et al.' - else: - myauthor = '' - return myauthor - + authorlist = self.editions.all()[0].authors.all() + if authorlist.count() == 1: + myauthor = authorlist[0].name + elif authorlist.count() > 1: + myauthor = authorlist[0].name + ' et al.' + else: + myauthor = '' + return myauthor + def last_campaign(self): try: last = self.campaigns.order_by('-created')[0] @@ -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 diff --git a/core/search.py b/core/search.py index 2484549e..9dcb4c82 100644 --- a/core/search.py +++ b/core/search.py @@ -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 diff --git a/core/tests.py b/core/tests.py index af5ace3f..6f4b76ea 100755 --- a/core/tests.py +++ b/core/tests.py @@ -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') diff --git a/frontend/templates/search.html b/frontend/templates/search.html index 7f6db2f2..16381e44 100644 --- a/frontend/templates/search.html +++ b/frontend/templates/search.html @@ -10,12 +10,12 @@ which overrides display: none in the stylesheet. Sneaky! --> {% endblock %} @@ -26,8 +26,8 @@ $(document).ready(function(){
- {% include "explore.html" %} -
+ {% include "explore.html" %} +
@@ -80,6 +80,18 @@ $(document).ready(function(){ book list status
+
+ {% if result.epub %} + + epub + + {% endif %} + {% if result.pdf %} + + pdf + + {% endif %} +
diff --git a/frontend/templates/supporter.html b/frontend/templates/supporter.html index 39e32636..0d45052a 100644 --- a/frontend/templates/supporter.html +++ b/frontend/templates/supporter.html @@ -57,12 +57,12 @@ which overrides display: none in the stylesheet. Sneaky! --> @@ -125,14 +125,14 @@ how do I integrate the your wishlist thing with the tabs thing?
- {% ifequal supporter request.user %} + {% ifequal supporter request.user %}
-
- {% csrf_token %} + + {% csrf_token %}

Your Tagline

- {{ profile_form.tagline }} + {{ profile_form.tagline }} - +
@@ -182,7 +182,7 @@ how do I integrate the your wishlist thing with the tabs thing?
- +
{% endifequal %}
@@ -200,8 +200,8 @@ how do I integrate the your wishlist thing with the tabs thing?
- {% include "explore.html" %} -
+ {% include "explore.html" %} +
@@ -257,13 +257,13 @@ how do I integrate the your wishlist thing with the tabs thing? Book name
- {{ work.author }} -
+ {{ work.author }} +
{% ifequal supporter request.user %}
Remove from Wishlist @@ -282,15 +282,27 @@ how do I integrate the your wishlist thing with the tabs thing?
{% endif %}{% endif %}{% endifequal %}
- Status: {{ work.last_campaign_status }} -
-
-
- book list status -
-
100%
-
-
+ Status: {{ work.last_campaign_status }} +
+
+
+ book list status +
+
100%
+
+
+
+ {% if work.first_epub %} + + epub + + {% endif %} + {% if work.first_pdf %} + + pdf + + {% endif %} +
diff --git a/frontend/views.py b/frontend/views.py index 5d5be81b..82ae3157 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -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: diff --git a/static/images/unglued.png b/static/images/unglued.png new file mode 100644 index 0000000000000000000000000000000000000000..d71edccd0276f3476797cacdfbd9bdbc56ffebc4 GIT binary patch literal 526 zcmV+p0`dKcP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipq= z6doTOOm<=b00E9kL_t(o!|j+sPQpMGhCc}hz!O+cV7qUEy#S%?jj~}|xB!S3K(=ns zuvg;&sxM_ZiF$(J2t9%eXVI8W5s)+{^KT}3FPZnvKX3Ei5j*N`_0a{MN>bB7=wDal zZwH}2+O=+j-Q`>2?G1TM4C1GH9hrj