commit
f9f58b6587
|
@ -1346,6 +1346,14 @@ class Work(models.Model):
|
|||
return True
|
||||
return False
|
||||
|
||||
def lib_thanked(self, user):
|
||||
if user.is_anonymous():
|
||||
return False
|
||||
lib_license=self.get_lib_license(user)
|
||||
if lib_license and lib_license.thanked:
|
||||
return True
|
||||
return False
|
||||
|
||||
def in_library(self,user):
|
||||
if user.is_anonymous():
|
||||
return False
|
||||
|
@ -1412,6 +1420,10 @@ class Work(models.Model):
|
|||
def borrowable(self):
|
||||
return self.acqs.filter(license=LIBRARY, refreshes__lt=now()).count()>0
|
||||
|
||||
@property
|
||||
def thanked(self):
|
||||
return self.acqs.filter(license=THANKED).count()>0
|
||||
|
||||
@property
|
||||
def borrowable_acq(self):
|
||||
for acq in self.acqs.filter(license=LIBRARY, refreshes__lt=now()):
|
||||
|
|
|
@ -90,9 +90,11 @@
|
|||
{% if in_library %}
|
||||
{% if borrowable %}
|
||||
<p>Available in your library now!</p>
|
||||
{% else %}{% if lib_thanked %}
|
||||
<p>Supported by your library!</p>
|
||||
{% else %}
|
||||
<p>Available in your library on<br />{{ next_acq.refreshes|date:"M j, Y" }}</p>
|
||||
{% endif %}
|
||||
{% endif %}{% endif %}
|
||||
{% else %}
|
||||
{% ifequal work.last_campaign.type 1 %}
|
||||
<b>UNGLUE IT!</b>
|
||||
|
|
|
@ -50,6 +50,13 @@ $j(document).ready(function() {
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if lib_thanked %}
|
||||
<div style="text-align: center; padding: 20px;">
|
||||
<div style="background: #edf3f4; padding: 10px; width:35%; display: inline; ">
|
||||
Your library has supported this free book!
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if amount %}
|
||||
<div style="text-align: center; padding: 20px;">
|
||||
<div style="background: #edf3f4; padding: 10px; width:35%; display: inline; ">
|
||||
|
|
|
@ -15,6 +15,7 @@ def purchased(context):
|
|||
user_license = work.get_user_license(user)
|
||||
context['borrowable'] = work.borrowable(user)
|
||||
context['in_library'] = work.in_library(user)
|
||||
context['lib_thanked'] = work.lib_thanked(user)
|
||||
except AttributeError:
|
||||
user_license = None
|
||||
context['borrowable'] = None
|
||||
|
|
|
@ -2618,6 +2618,8 @@ class DownloadView(PurchaseView):
|
|||
return False
|
||||
elif self.user_license and self.user_license.thanked:
|
||||
return self.request.REQUEST.has_key('offer_id')
|
||||
elif self.lib_thanked:
|
||||
return False
|
||||
elif self.campaign.status != 'ACTIVE':
|
||||
return self.request.REQUEST.has_key('testmode')
|
||||
else:
|
||||
|
@ -2646,6 +2648,7 @@ class DownloadView(PurchaseView):
|
|||
self.work = safe_get_work(self.kwargs["work_id"])
|
||||
self.campaign = self.work.last_campaign()
|
||||
self.user_license = self.work.get_user_license(self.request.user)
|
||||
self.lib_thanked = self.work.lib_thanked(self.request.user)
|
||||
self.data = {
|
||||
'preapproval_amount':self.get_preapproval_amount(),
|
||||
'anonymous':True if self.request.user.is_anonymous() else self.request.user.profile.anon_pref,
|
||||
|
@ -2739,6 +2742,7 @@ class DownloadView(PurchaseView):
|
|||
'site': site,
|
||||
'action': "Contribution",
|
||||
'user_license': self.user_license,
|
||||
'lib_thanked': self.lib_thanked,
|
||||
'amount': self.request.session.pop('amount') if self.request.session.has_key('amount') else None,
|
||||
})
|
||||
return context
|
||||
|
@ -2760,7 +2764,7 @@ def borrow(request, work_id):
|
|||
acq=work.get_lib_license(request.user).borrowable_acq
|
||||
if acq:
|
||||
borrowed = acq.borrow(request.user)
|
||||
return download(request, work_id)
|
||||
return DownloadView.as_view()(request, work=work)
|
||||
else:
|
||||
# shouldn't happen
|
||||
return work(request, work_id)
|
||||
|
@ -2790,7 +2794,7 @@ def download_ebook(request, ebook_id):
|
|||
def download_purchased(request, work_id):
|
||||
if request.user.is_anonymous:
|
||||
HttpResponseRedirect('/accounts/login/download/')
|
||||
return download(request, work_id)
|
||||
return DownloadView.as_view()(request, work_id)
|
||||
|
||||
def download_campaign(request, work_id, format):
|
||||
work = safe_get_work(work_id)
|
||||
|
|
|
@ -88,7 +88,7 @@ class Authenticator:
|
|||
return self.backend_class.authenticator().process(self, success_url, deny_url)
|
||||
|
||||
def allowed(self):
|
||||
return self.backend_class.authenticate(self.request, self.library)
|
||||
return self.backend_class().authenticate(self.request, self.library)
|
||||
|
||||
class BaseLibraryView:
|
||||
model = Library
|
||||
|
|
Loading…
Reference in New Issue