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