rudimentary download page plus logic to serve it
parent
07a50bfa45
commit
a6e034a36a
|
@ -0,0 +1,53 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% with work.title as title %}
|
||||
{% block title %}
|
||||
— Downloads for {{ work.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link type="text/css" rel="stylesheet" href="/static/css/download.css" />
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script type="text/javascript" src="/static/js/wishlist.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="download_container">
|
||||
<h2>Downloads for {{ work.title }}</h2>
|
||||
{% if unglued_ebook %}
|
||||
<div class="unglued">
|
||||
<h3>Get the unglued edition!</h3>
|
||||
<div class="ebook_download">
|
||||
<img src="{{ unglued_ebook.rights_badge }}">
|
||||
<a href="{{ unglued_ebook.0.url }}">{{ unglued_ebook.format }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if other_ebooks %}
|
||||
{% if unglued_ebook %}<h4>Freely available editions</h4>{% endif %}
|
||||
{% comment %}
|
||||
the header is only necessary if we have an unglued edition we're distinguishing
|
||||
non-unglued editions from
|
||||
{% endcomment %}
|
||||
{% for edition in other_ebooks %}
|
||||
<div class="ebook_download clearfix">
|
||||
{% with edition.url as url %}
|
||||
<a href="{{ url }}"><img src="{{ edition.rights_badge }}"></a>
|
||||
<a href="{{ url }}">{{ edition.format }}</a>
|
||||
{% endwith %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if unglued_ebook or other_ebooks %}
|
||||
blah blah download instructions
|
||||
{% else %}
|
||||
<p id="content-block">There are no freely available downloads of <I>{{ work.title }}</I> right now. {% if not work in request.user.wishlist.works.all %}Would you like there to be? <a class="add-wishlist"><span class="work_id" id="w{{ work.id }}">Add this book to your wishlist.</span></a>{% else %}Ask your friends to add it to their wishlists!{% endif %}</p>
|
||||
|
||||
<p>If you know of a Creative-Commons-licensed or US public domain edition of this book, you can add it through the <a href="{% url work work.id %}?tab=4">Rights tab of the book page</a>.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% endwith %}
|
|
@ -28,16 +28,6 @@ $j(document).ready(function(){
|
|||
$j(this).next().toggle();
|
||||
});
|
||||
});
|
||||
$j(document).ready(function(){
|
||||
$j('.show_more_ebooks').click(function(){
|
||||
if ($j(this).html() == '<br>hide downloads') {
|
||||
$j(this).html('<br>more downloads...')
|
||||
} else {
|
||||
$j(this).html('<br>hide downloads')
|
||||
}
|
||||
$j(this).next().toggle();
|
||||
});
|
||||
});
|
||||
$j(document).ready(function(){
|
||||
var img = $j('#book-detail-img');
|
||||
var googimg = $j('#find-google img');
|
||||
|
@ -135,42 +125,14 @@ $j(document).ready(function(){
|
|||
<div class="btn_support"><form action="{% url pledge work_id %}" method="get"><input type="submit" value="Support" /></form></div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if status == 'SUCCESSFUL' %}
|
||||
{% if work.first_ebook %}
|
||||
<div class="btn_support">
|
||||
{% if unglued_ebook %}
|
||||
<a href="{{ unglued_ebook.url }}">Download</a>
|
||||
{% else %}
|
||||
Coming soon!
|
||||
{% endif %}
|
||||
<a href="{% url download work_id %}" id="ebookDownload" class="fakeinput">Download</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if work.first_ebook %}
|
||||
<div class="get-book">
|
||||
<label>Read it now!</label>
|
||||
<span class="find-link">
|
||||
{% for ebook in work.ebooks %}
|
||||
{% if forloop.first %}
|
||||
<span class="first_ebook">
|
||||
{% endif %}
|
||||
{% if forloop.counter == 2 %}
|
||||
</span>
|
||||
<span class="show_more_ebooks"><br />More downloads...</span>
|
||||
<span class="more_ebooks">
|
||||
{% endif %}
|
||||
{% if not forloop.first %}
|
||||
<br />
|
||||
{% endif %}
|
||||
<a href="{{ ebook.url }}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt=" {{ ebook.format }} at {{ebook.provider}}" title=" {{ ebook.format }} at {{ebook.provider}}" /><img src="{{ebook.rights_badge}}" height="31" width="88" alt="{{ebook.rights}}" title="{{ebook.rights}}" /></a>
|
||||
{% if forloop.last %}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="find-book">
|
||||
<label>Learn more at...</label>
|
||||
<div class="find-link">
|
||||
|
|
|
@ -44,6 +44,7 @@ urlpatterns = patterns(
|
|||
url(r"^work/(?P<work_id>\d+)/preview/$", "work", {'action': 'preview'}, name="work_preview"),
|
||||
url(r"^work/(?P<work_id>\d+)/acks/$", "work", {'action': 'acks'}, name="work_acks"),
|
||||
url(r"^work/(?P<work_id>\d+)/lockss/$", "lockss", name="lockss"),
|
||||
url(r"^work/(?P<work_id>\d+)/download/$", "download", name="download"),
|
||||
url(r"^work/\d+/acks/images/(?P<file_name>[\w\.]*)$", "static_redirect_view",{'dir': 'images'}),
|
||||
url(r"^work/(?P<work_id>\d+)/librarything/$", "work_librarything", name="work_librarything"),
|
||||
url(r"^work/(?P<work_id>\d+)/goodreads/$", "work_goodreads", name="work_goodreads"),
|
||||
|
|
|
@ -94,6 +94,16 @@ def next(request):
|
|||
return response
|
||||
else:
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
def safe_get_work(work_id):
|
||||
try:
|
||||
work = models.Work.objects.get(id = work_id)
|
||||
except models.Work.DoesNotExist:
|
||||
try:
|
||||
work = models.WasWork.objects.get(was = work_id).work
|
||||
except models.WasWork.DoesNotExist:
|
||||
raise Http404
|
||||
return work
|
||||
|
||||
def home(request, landing=False):
|
||||
if request.user.is_authenticated() and landing == False:
|
||||
|
@ -116,15 +126,10 @@ def acks(request, work):
|
|||
|
||||
|
||||
def work(request, work_id, action='display'):
|
||||
try:
|
||||
work = models.Work.objects.get(id = work_id)
|
||||
except models.Work.DoesNotExist:
|
||||
try:
|
||||
work = models.WasWork.objects.get(was = work_id).work
|
||||
except models.WasWork.DoesNotExist:
|
||||
raise Http404
|
||||
work = safe_get_work(work_id)
|
||||
if action == "acks":
|
||||
return acks( request, work)
|
||||
|
||||
if request.method == 'POST' and not request.user.is_anonymous():
|
||||
activetab = '4'
|
||||
else:
|
||||
|
@ -135,6 +140,8 @@ def work(request, work_id, action='display'):
|
|||
activetab = '1';
|
||||
except:
|
||||
activetab = '1';
|
||||
|
||||
context = {}
|
||||
campaign = work.last_campaign()
|
||||
if campaign and campaign.edition:
|
||||
editions = [campaign.edition]
|
||||
|
@ -146,6 +153,12 @@ def work(request, work_id, action='display'):
|
|||
pledged = None
|
||||
|
||||
countdown = ""
|
||||
|
||||
try:
|
||||
assert not (work.last_campaign_status() == 'ACTIVE' and work.first_ebook())
|
||||
except:
|
||||
logger.warning("Campaign running for %w when ebooks are already available: why?" % work.title )
|
||||
|
||||
if work.last_campaign_status() == 'ACTIVE':
|
||||
from math import ceil
|
||||
time_remaining = campaign.deadline - now()
|
||||
|
@ -166,8 +179,8 @@ def work(request, work_id, action='display'):
|
|||
countdown = "in %s minutes" % str(time_remaining.seconds/60 + 1)
|
||||
else:
|
||||
countdown = "right now"
|
||||
elif work.last_campaign_status() == 'SUCCESSFUL':
|
||||
unglued_ebook = work.ebooks().filter(unglued=True)
|
||||
context.update({ 'countdown': countdown })
|
||||
|
||||
if action == 'preview':
|
||||
work.last_campaign_status = 'ACTIVE'
|
||||
|
||||
|
@ -175,6 +188,7 @@ def work(request, work_id, action='display'):
|
|||
pubdate = work.publication_date[:4]
|
||||
except IndexError:
|
||||
pubdate = 'unknown'
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
claimform = UserClaimForm( request.user, data={'claim-work':work.pk, 'claim-user': request.user.id}, prefix = 'claim')
|
||||
for edition in editions:
|
||||
|
@ -193,6 +207,7 @@ def work(request, work_id, action='display'):
|
|||
edition.ebook_form = EbookForm( instance= models.Ebook(user = request.user, edition = edition, provider = 'x' ), prefix = 'ebook_%d'%edition.id)
|
||||
else:
|
||||
claimform = None
|
||||
|
||||
if campaign:
|
||||
# pull up premiums explicitly tied to the campaign or generic premiums
|
||||
premiums = campaign.effective_premiums()
|
||||
|
@ -232,7 +247,6 @@ def work(request, work_id, action='display'):
|
|||
'alert': alert,
|
||||
'claimstatus': claimstatus,
|
||||
'rights_holder_name': rights_holder_name,
|
||||
'countdown': countdown,
|
||||
})
|
||||
|
||||
def new_edition(request, work_id, edition_id, by=None):
|
||||
|
@ -2030,14 +2044,34 @@ def campaign_archive_js(request):
|
|||
return response
|
||||
|
||||
def lockss(request, work_id):
|
||||
try:
|
||||
work = models.Work.objects.get(id = work_id)
|
||||
except models.Work.DoesNotExist:
|
||||
try:
|
||||
work = models.WasWork.objects.get(was = work_id).work
|
||||
except models.WasWork.DoesNotExist:
|
||||
raise Http404
|
||||
work = safe_get_work(work_id)
|
||||
ebook = work.ebooks().filter(unglued=True)[0]
|
||||
authors = list(models.Author.objects.filter(editions__work=work).all())
|
||||
|
||||
return render(request, "lockss.html", {'work':work, 'ebook':ebook, 'authors':authors})
|
||||
return render(request, "lockss.html", {'work':work, 'ebook':ebook, 'authors':authors})
|
||||
|
||||
def download(request, work_id):
|
||||
context = {}
|
||||
work = safe_get_work(work_id)
|
||||
context.update({'work': work})
|
||||
|
||||
unglued_ebook = work.ebooks().filter(unglued=True)
|
||||
other_ebooks = work.ebooks().filter(unglued=False)
|
||||
|
||||
try:
|
||||
ungluedcount = unglued_ebook.count()
|
||||
assert (ungluedcount == 1 or ungluedcount == 0)
|
||||
except:
|
||||
logger.warning("There is more than one unglued edition for %w" % work.title)
|
||||
|
||||
try:
|
||||
unglued_ebook = unglued_ebook[0]
|
||||
except:
|
||||
pass
|
||||
|
||||
context.update({
|
||||
'unglued_ebook': unglued_ebook,
|
||||
'other_ebooks': other_ebooks
|
||||
})
|
||||
|
||||
return render(request, "download.html", context)
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/* variables and mixins used in multiple less files go here */
|
||||
.header-text {
|
||||
height: 36px;
|
||||
line-height: 36px;
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
font-size: 13px;
|
||||
letter-spacing: -0.05em;
|
||||
}
|
||||
.panelborders {
|
||||
border-width: 1px 0px;
|
||||
border-style: solid none;
|
||||
border-color: #FFFFFF;
|
||||
}
|
||||
.roundedspan {
|
||||
border: 1px solid #d4d4d4;
|
||||
-moz-border-radius: 7px;
|
||||
-webkit-border-radius: 7px;
|
||||
border-radius: 7px;
|
||||
padding: 1px;
|
||||
color: #fff;
|
||||
margin: 0 8px 0 0;
|
||||
display: inline-block;
|
||||
}
|
||||
.roundedspan > span {
|
||||
padding: 7px 7px;
|
||||
min-width: 15px;
|
||||
-moz-border-radius: 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
}
|
||||
.roundedspan > span .hovertext {
|
||||
display: none;
|
||||
}
|
||||
.roundedspan > span:hover .hovertext {
|
||||
display: inline;
|
||||
}
|
||||
.mediaborder {
|
||||
padding: 5px;
|
||||
border: solid 5px #EDF3F4;
|
||||
}
|
||||
.google_signup_div {
|
||||
padding: 14px 0;
|
||||
}
|
||||
.google_signup_div div {
|
||||
height: 24px;
|
||||
line-height: 24px;
|
||||
float: left;
|
||||
padding-left: 5px;
|
||||
}
|
||||
.google_signup_div img {
|
||||
float: left;
|
||||
height: 24px;
|
||||
width: 24px;
|
||||
}
|
||||
.actionbuttons {
|
||||
width: auto;
|
||||
height: 36px;
|
||||
line-height: 36px;
|
||||
background: #8dc63f;
|
||||
-moz-border-radius: 32px;
|
||||
-webkit-border-radius: 32px;
|
||||
border-radius: 32px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
padding: 0 15px;
|
||||
border: none;
|
||||
margin: 5px 0;
|
||||
}
|
||||
.errors {
|
||||
-moz-border-radius: 16px 16px 0 0;
|
||||
-webkit-border-radius: 16px 16px 0 0;
|
||||
border-radius: 16px 16px 0 0;
|
||||
border: solid #e35351 3px;
|
||||
clear: both;
|
||||
width: 90%;
|
||||
height: auto;
|
||||
line-height: 16px;
|
||||
padding: 7px 0;
|
||||
font-weight: bold;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
.errors li {
|
||||
list-style: none;
|
||||
border: none;
|
||||
}
|
||||
.ebook_download {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.ebook_download a {
|
||||
margin: auto 5px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.ebook_download img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
.unglued {
|
||||
border: solid 2px #8dc63f;
|
||||
margin-left: -2px;
|
||||
padding: 5px;
|
||||
}
|
||||
.unglued h3 {
|
||||
margin-top: 5px;
|
||||
}
|
||||
a.add-wishlist .on-wishlist,
|
||||
a.success,
|
||||
a.success:hover {
|
||||
text-decoration: none;
|
||||
color: #3d4e53;
|
||||
}
|
||||
a.success,
|
||||
a.success:hover {
|
||||
cursor: default;
|
||||
}
|
||||
.download_container {
|
||||
width: 50%;
|
||||
margin: auto;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
@import "variables.less";
|
||||
|
||||
.ebook_download {
|
||||
a {
|
||||
margin: auto 5px;
|
||||
font-size: @font-size-larger;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.unglued {
|
||||
border: solid 2px @call-to-action;
|
||||
margin-left: -2px;
|
||||
padding: 5px;
|
||||
|
||||
h3 {
|
||||
margin-top: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
a.add-wishlist .on-wishlist, a.success, a.success:hover {
|
||||
text-decoration: none;
|
||||
color: @text-blue;
|
||||
}
|
||||
|
||||
a.success, a.success:hover {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.download_container {
|
||||
width: 50%;
|
||||
margin: auto;
|
||||
}
|
Loading…
Reference in New Issue