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

@ -103,8 +103,8 @@ class Campaign(models.Model):
return self return self
def supporters(self): def supporters(self):
translist = self.transactions().values_list('user', flat=True).distinct() translist = self.transactions().values_list('user', flat=True).distinct()
return translist return translist
class Work(models.Model): class Work(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
@ -118,14 +118,14 @@ class Work(models.Model):
return self.editions.all()[0].cover_image_thumbnail() return self.editions.all()[0].cover_image_thumbnail()
def author(self): def author(self):
authorlist = self.editions.all()[0].authors.all() authorlist = self.editions.all()[0].authors.all()
if authorlist.count() == 1: if authorlist.count() == 1:
myauthor = authorlist[0].name myauthor = authorlist[0].name
elif authorlist.count() > 1: elif authorlist.count() > 1:
myauthor = authorlist[0].name + ' et al.' myauthor = authorlist[0].name + ' et al.'
else: else:
myauthor = '' myauthor = ''
return myauthor return myauthor
def last_campaign(self): def last_campaign(self):
try: try:
@ -160,6 +160,19 @@ class Work(models.Model):
status = percent; status = percent;
return status; 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): def __unicode__(self):
return self.title return self.title

View File

@ -7,8 +7,6 @@ def gluejar_search(q):
results = [] results = []
for item in googlebooks_search(q)['items']: 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'] v = item['volumeInfo']
r = {'title': v.get('title', ""), r = {'title': v.get('title', ""),
'description': v.get('description', ""), 'description': v.get('description', ""),
@ -36,6 +34,14 @@ def gluejar_search(q):
else: else:
r['image'] = "" 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) results.append(r)
return results 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.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') 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): def test_add_no_ebook(self):
# this edition lacks an ebook, but we should still be able to load it # this edition lacks an ebook, but we should still be able to load it
e = bookloader.add_by_isbn('0465019358') e = bookloader.add_by_isbn('0465019358')

View File

@ -10,12 +10,12 @@
which overrides display: none in the stylesheet. Sneaky! --> which overrides display: none in the stylesheet. Sneaky! -->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$('#toggle-list').click(function(){ $('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview"); $('div.panelview').addClass("listview").removeClass("panelview");
}); });
$('#toggle-panel').click(function(){ $('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview"); $('div.listview').addClass("panelview").removeClass("listview");
}); });
}); });
</script> </script>
{% endblock %} {% endblock %}
@ -26,8 +26,8 @@ $(document).ready(function(){
<div id="main-container"> <div id="main-container">
<div class="js-main"> <div class="js-main">
<div id="js-leftcol"> <div id="js-leftcol">
{% include "explore.html" %} {% include "explore.html" %}
</div> </div>
<div id="js-maincol-fr"> <div id="js-maincol-fr">
<div class="js-maincol-inner"> <div class="js-maincol-inner">
@ -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" /> <img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" />
</span> </span>
</div> </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 none">
<div class="unglue-this-inner1"> <div class="unglue-this-inner1">
<div class="unglue-this-inner2"> <div class="unglue-this-inner2">

View File

@ -57,12 +57,12 @@
which overrides display: none in the stylesheet. Sneaky! --> which overrides display: none in the stylesheet. Sneaky! -->
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
$('#toggle-list').click(function(){ $('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview"); $('div.panelview').addClass("listview").removeClass("panelview");
}); });
$('#toggle-panel').click(function(){ $('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview"); $('div.listview').addClass("panelview").removeClass("listview");
}); });
}); });
</script> </script>
@ -125,14 +125,14 @@ how do I integrate the your wishlist thing with the tabs thing?
<div class="user-block4"> <div class="user-block4">
<div class="social"> <div class="social">
{% if supporter.profile.home_url %} {% if supporter.profile.home_url %}
<a href="{{ supporter.profile.home_url }}"> <a href="{{ supporter.profile.home_url }}">
<img src="/static/images/header/icon-home.png" alt="{{ supporter }}'s Homepage" title="{{ supporter }}'s Homepage" /> <img src="/static/images/header/icon-home.png" alt="{{ supporter }}'s Homepage" title="{{ supporter }}'s Homepage" />
</a> </a>
{% endif %} {% endif %}
<a href="#"><img src="/static/images/header/icon-facebook.png" alt="{{ supporter }}'s Facebook" title="{{ supporter }}'s Facebook" /></a> <a href="#"><img src="/static/images/header/icon-facebook.png" alt="{{ supporter }}'s Facebook" title="{{ supporter }}'s Facebook" /></a>
{% if supporter.profile.twitter_id %} {% if supporter.profile.twitter_id %}
<a href="https://twitter.com/#!/{{ supporter.profile.twitter_id }}"> <a href="https://twitter.com/#!/{{ supporter.profile.twitter_id }}">
<img src="/static/images/header/icon-twitter.png" alt="{{ supporter }}'s Twitter" title="{{ supporter }}'s Twitter" /> <img src="/static/images/header/icon-twitter.png" alt="{{ supporter }}'s Twitter" title="{{ supporter }}'s Twitter" />
</a> </a>
{% endif %} {% endif %}
<a href="#"><img src="/static/images/header/icon-google.png" alt="google" title="google" /></a> <a href="#"><img src="/static/images/header/icon-google.png" alt="google" title="google" /></a>
@ -147,16 +147,16 @@ how do I integrate the your wishlist thing with the tabs thing?
<span class="user-status-title">I am ungluing</span> <span class="user-status-title">I am ungluing</span>
</div> </div>
</div> </div>
{% ifequal supporter request.user %} {% ifequal supporter request.user %}
<div class="user-block-hide"> <div class="user-block-hide">
<form method="POST" action=""> <form method="POST" action="">
{% csrf_token %} {% csrf_token %}
<div class="block block1"> <div class="block block1">
<div class="block-inner"> <div class="block-inner">
<h3><a class="profile-edit" href="#">Your Tagline</a></h3> <h3><a class="profile-edit" href="#">Your Tagline</a></h3>
{{ profile_form.tagline }} {{ profile_form.tagline }}
<input class="profile-save" type="submit" name="submit" value="Update" id="submit"> <input class="profile-save" type="submit" name="submit" value="Update" id="submit">
</div> </div>
</div> </div>
@ -182,7 +182,7 @@ how do I integrate the your wishlist thing with the tabs thing?
</div> </div>
</div> </div>
</form> </form>
</div> </div>
{% endifequal %} {% endifequal %}
</div> </div>
@ -200,8 +200,8 @@ how do I integrate the your wishlist thing with the tabs thing?
<div id="main-container"> <div id="main-container">
<div class="js-main"> <div class="js-main">
<div id="js-leftcol"> <div id="js-leftcol">
{% include "explore.html" %} {% include "explore.html" %}
</div> </div>
<div id="js-maincol-fr"> <div id="js-maincol-fr">
<div class="js-maincol-inner"> <div class="js-maincol-inner">
@ -257,13 +257,13 @@ how do I integrate the your wishlist thing with the tabs thing?
<a href="#"><img src="{{ work.cover_image_thumbnail }}" alt="Book name" title="book name" /></a> <a href="#"><img src="{{ work.cover_image_thumbnail }}" alt="Book name" title="book name" /></a>
</div> </div>
<div class="listview book-name"> <div class="listview book-name">
<span> <span>
<a href="{% url work work.id %}">{{ work.title }}</a> <a href="{% url work work.id %}">{{ work.title }}</a>
</span> </span>
</div> </div>
<div class="listview author"> <div class="listview author">
<span id="{{ work.author }}">{{ work.author }}</span> <span id="{{ work.author }}">{{ work.author }}</span>
</div> </div>
{% ifequal supporter request.user %} {% ifequal supporter request.user %}
<div class="listview remove-wishlist"> <div class="listview remove-wishlist">
<span id="{{ work.id }}">Remove from Wishlist</span> <span id="{{ work.id }}">Remove from Wishlist</span>
@ -282,15 +282,27 @@ how do I integrate the your wishlist thing with the tabs thing?
</div> </div>
{% endif %}{% endif %}{% endifequal %} {% endif %}{% endif %}{% endifequal %}
<div class="listview booklist-status"> <div class="listview booklist-status">
<span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">{{ work.last_campaign_status }}</span> <span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">{{ work.last_campaign_status }}</span>
</div> </div>
<div class="listview icons"> <div class="listview icons">
<div class="booklist-status-img"> <div class="booklist-status-img">
<img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" /> <img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" />
</div> </div>
<div class="booklist-status-label">100%</div> <div class="booklist-status-label">100%</div>
<div class="right_add"><img src="/static/images/book-panel/add_gray.png" border="0" /></div> <div class="right_add"><img src="/static/images/book-panel/add_gray.png" border="0" /></div>
</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 none">
<div class="unglue-this-inner1"> <div class="unglue-this-inner1">
<div class="unglue-this-inner2"> <div class="unglue-this-inner2">

View File

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

BIN
static/images/unglued.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B