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
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

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

@ -10,12 +10,12 @@
which overrides display: none in the stylesheet. Sneaky! -->
<script type="text/javascript">
$(document).ready(function(){
$('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview");
});
$('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview");
});
$('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview");
});
$('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview");
});
});
</script>
{% endblock %}
@ -26,8 +26,8 @@ $(document).ready(function(){
<div id="main-container">
<div class="js-main">
<div id="js-leftcol">
{% include "explore.html" %}
</div>
{% include "explore.html" %}
</div>
<div id="js-maincol-fr">
<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" />
</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

@ -57,12 +57,12 @@
which overrides display: none in the stylesheet. Sneaky! -->
<script type="text/javascript">
$(document).ready(function(){
$('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview");
});
$('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview");
});
$('#toggle-list').click(function(){
$('div.panelview').addClass("listview").removeClass("panelview");
});
$('#toggle-panel').click(function(){
$('div.listview').addClass("panelview").removeClass("listview");
});
});
</script>
@ -125,14 +125,14 @@ how do I integrate the your wishlist thing with the tabs thing?
<div class="user-block4">
<div class="social">
{% if 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" />
</a>
<a href="{{ supporter.profile.home_url }}">
<img src="/static/images/header/icon-home.png" alt="{{ supporter }}'s Homepage" title="{{ supporter }}'s Homepage" />
</a>
{% endif %}
<a href="#"><img src="/static/images/header/icon-facebook.png" alt="{{ supporter }}'s Facebook" title="{{ supporter }}'s Facebook" /></a>
{% if 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>
{% endif %}
<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>
</div>
</div>
{% ifequal supporter request.user %}
{% ifequal supporter request.user %}
<div class="user-block-hide">
<form method="POST" action="">
{% csrf_token %}
<form method="POST" action="">
{% csrf_token %}
<div class="block block1">
<div class="block-inner">
<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>
@ -182,7 +182,7 @@ how do I integrate the your wishlist thing with the tabs thing?
</div>
</div>
</form>
</form>
</div>
{% endifequal %}
</div>
@ -200,8 +200,8 @@ how do I integrate the your wishlist thing with the tabs thing?
<div id="main-container">
<div class="js-main">
<div id="js-leftcol">
{% include "explore.html" %}
</div>
{% include "explore.html" %}
</div>
<div id="js-maincol-fr">
<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>
</div>
<div class="listview book-name">
<span>
<a href="{% url work work.id %}">{{ work.title }}</a>
</span>
<span>
<a href="{% url work work.id %}">{{ work.title }}</a>
</span>
</div>
<div class="listview author">
<span id="{{ work.author }}">{{ work.author }}</span>
</div>
<span id="{{ work.author }}">{{ work.author }}</span>
</div>
{% ifequal supporter request.user %}
<div class="listview remove-wishlist">
<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>
{% endif %}{% endif %}{% endifequal %}
<div class="listview booklist-status">
<span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">{{ work.last_campaign_status }}</span>
</div>
<div class="listview icons">
<div class="booklist-status-img">
<img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" />
</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>
<span class="booklist-status-label">Status:&nbsp;</span><span class="booklist-status-text">{{ work.last_campaign_status }}</span>
</div>
<div class="listview icons">
<div class="booklist-status-img">
<img src="/static/images/images/icon-book-37by25-4.png" title="book list status" alt="book list status" />
</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>
<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