Merge pull request #458 from Gluejar/email_message

sharing issues [fix #88552056][fix #88631150]
pull/1/head
Raymond Yee 2015-02-25 11:19:26 -08:00
commit 2390c322a4
6 changed files with 44 additions and 25 deletions

View File

@ -122,4 +122,6 @@ class ApiTests(TestCase):
def test_widget(self):
r = self.client.get('/api/widget/0441007465/')
self.assertEqual(r.status_code, 200)
r = self.client.get('/api/widget/%s/'%self.work_id)
self.assertEqual(r.status_code, 200)

View File

@ -39,23 +39,25 @@ def editions(request):
def widget(request,isbn):
"""
supply info for book panel
supply info for book panel. parameter is named isbn for historical reasons. can be isbn or work_id
"""
if len(isbn)==10:
isbn = regluit.core.isbn.convert_10_to_13(isbn)
if len(isbn)==13:
try:
identifier = models.Identifier.objects.get( Q( type = 'isbn', value = isbn ))
work = identifier.work
edition = identifier.edition
except models.Identifier.DoesNotExist:
return render_to_response('widget.html',
{'isbn':isbn,'edition':None, 'work':None, 'campaign':None,},
{ 'work':None,},
context_instance=RequestContext(request)
)
else:
work= models.safe_get_work(isbn)
return render_to_response('widget.html',
{'isbn':isbn,'edition':edition, 'work':work, 'campaign':work.last_campaign(), },
{'work':work, },
context_instance=RequestContext(request)
)

View File

@ -1783,6 +1783,19 @@ class WasWork(models.Model):
moved = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User, null=True)
def safe_get_work(work_id):
"""
use this rather than querying the db directly for a work by id
"""
try:
work = Work.objects.get(id = work_id)
except Work.DoesNotExist:
try:
work = WasWork.objects.get(was = work_id).work
except WasWork.DoesNotExist:
raise Work.DoesNotExist()
return work
FORMAT_CHOICES = (('pdf','PDF'),( 'epub','EPUB'), ('html','HTML'), ('text','TEXT'), ('mobi','MOBI'))
def path_for_file(instance, filename):

View File

@ -1,4 +1,9 @@
Help me unglue one of my favorite books, "{{ work.title }}" on Unglue.it:
{% if work.is_free %}"{{ work.title }}" is a free ebook on Unglue.it:
https://{{site}}{% url work work.id %}
If enough of us fave this book, Unglue.it may start a campaign to pay the creator and make the ebook free to everyone on earth.
You can download it and read it on your favorite device.
{% else %}Help me unglue one of my favorite books, "{{ work.title }}" on Unglue.it:
https://{{site}}{% url work work.id %}
If enough of us fave this book, Unglue.it may start a campaign to pay the creator and make the ebook free to everyone on earth.{% endif %}

View File

@ -4,7 +4,7 @@
{% load purchased %}
{% load lib_acqs %}
{% block title %}—
{% if work.first_ebook %}
{% if work.is_free %}
{{ work.title }} is a Free eBook
{% else %}
Help us make {{ work.title }} a Free eBook!
@ -416,7 +416,7 @@
{% endif %}
{% endif %}
{% endif %}
{% if work.first_ebook %}
{% if work.is_free %}
<h4>Downloads</h4>
<div class="pledged-info">
This work has been downloaded {{ work.download_count }} times via unglue.it ebook links.
@ -515,7 +515,7 @@
{% endif %}{% endif %}
{% endif %}{% endif %}
{% else %}
{% if work.first_ebook %}
{% if work.is_free %}
<div class="btn_support">
<a href="{% url download work_id %}" class="hijax"><span>Download</span></a>
</div>
@ -539,7 +539,7 @@
<div class="jsmod-content">
<ul class="social menu">
<a href="https://www.facebook.com/sharer.php?u={{request.build_absolute_uri|urlencode:"" }}"><li class="facebook first"><span>Facebook</span></li></a>
{% if work.first_ebook %}
{% if work.is_free %}
<a href="https://twitter.com/intent/tweet?url={{request.build_absolute_uri|urlencode:"" }}&amp;text=I%27m%20enjoying%20{{ work.title|urlencode }}%2C%20a%20free%2C%20DRM%2Dfree%20ebook%2E%20You%20can%20too%21"><li class="twitter"><span>Twitter</span></li></a>
{% else %}
{% ifequal status 'SUCCESSFUL' %}
@ -552,7 +552,7 @@
<a href="#" id="embed"><li class="embed"><span>Embed</span></li></a>
</ul>
<div id="widgetcode">
Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;iframe src="https://{{request.META.HTTP_HOST}}/api/widget/{{work.first_isbn_13}}/" width="152" height="325" frameborder="0"&gt;&lt;/iframe&gt;</textarea></div>
Copy/paste this into your site:<br /><textarea rows="7" cols="22">&lt;iframe src="https://{{request.META.HTTP_HOST}}/api/widget/{{work.id}}/" width="152" height="325" frameborder="0"&gt;&lt;/iframe&gt;</textarea></div>
</div>
</div>
{% if status == 'ACTIVE' %}
@ -750,7 +750,7 @@
{% endif %}
</div>
{% if request.user.libpref %}
{% if work.first_ebook or work.ebookfiles %}
{% if work.is_free or work.ebookfiles %}
<div id="libtools">
<p>for libraries...</p>
<form method="POST" id="record_form" action="{% url work_marc work.id %}">

View File

@ -202,11 +202,8 @@ def safe_get_work(work_id):
use this rather than querying the db directly for a work by id
"""
try:
work = models.Work.objects.get(id = work_id)
work = models.safe_get_work(work_id)
except models.Work.DoesNotExist:
try:
work = models.WasWork.objects.get(was = work_id).work
except models.WasWork.DoesNotExist:
raise Http404
return work
@ -2925,7 +2922,7 @@ def feature(request, work_id):
return render(request, "admins_only.html")
else:
work = safe_get_work(work_id)
if work.first_ebook():
if work.is_free:
work.featured = now()
work.save()
return HttpResponseRedirect(reverse('landing', args=[] ))