Merge branch 'master' into relaunch_ry

pull/1/head
Raymond Yee 2012-09-27 15:01:20 -07:00
commit d72df702aa
10 changed files with 79 additions and 29 deletions

View File

@ -497,6 +497,24 @@ class Identifier(models.Model):
class Meta: class Meta:
unique_together = ("type", "value") unique_together = ("type", "value")
@staticmethod
def set(type=None, value=None, edition=None, work=None):
# if there's already an id of this type for this work and edition, change it
# if not, create it. if the id exists and points to something else, change it.
identifier= Identifier.get_or_add(type=type, value=value, edition = edition, work=work)
if identifier.work.id != work.id:
identifier.work=work
identifier.save()
if identifier.edition and edition:
if identifier.edition.id != edition.id:
identifier.edition = edition
identifier.save()
others= Identifier.objects.filter(type=type, work=work, edition=edition).exclude(value=value)
if others.count()>0:
for other in others:
other.delete()
return identifier
@staticmethod @staticmethod
def get_or_add( type='goog', value=None, edition=None, work=None): def get_or_add( type='goog', value=None, edition=None, work=None):
try: try:
@ -696,6 +714,15 @@ class Work(models.Model):
self.num_wishes = Wishes.objects.filter(work=self).count() self.num_wishes = Wishes.objects.filter(work=self).count()
self.save() self.save()
def first_oclc(self):
preferred_id=self.preferred_edition.oclc
if preferred_id:
return preferred_id
try:
return self.identifiers.filter(type='oclc')[0].value
except IndexError:
return ''
def first_isbn_13(self): def first_isbn_13(self):
preferred_id=self.preferred_edition.isbn_13 preferred_id=self.preferred_edition.isbn_13
if preferred_id: if preferred_id:

View File

@ -644,11 +644,12 @@ class DownloadPageTest(TestCase):
eb2 = models.Ebook() eb2 = models.Ebook()
eb2.url = "http://example2.com" eb2.url = "http://example2.com"
eb2.edition = e2 eb2.edition = e2
eb2.format = 'mobi'
eb1.save() eb1.save()
eb2.save() eb2.save()
anon_client = Client() anon_client = Client()
response = anon_client.get("/work/%s/download/" % w.id) response = anon_client.get("/work/%s/download/" % w.id)
self.assertContains(response, "http://example.com", count=3) self.assertContains(response, "http://example.com", count=4)
self.assertContains(response, "http://example2.com", count=2) self.assertContains(response, "http://example2.com", count=3)

View File

@ -36,6 +36,15 @@ class EditionForm(forms.ModelForm):
'required': _("Yes, we need an ISBN."), 'required': _("Yes, we need an ISBN."),
} }
) )
oclcnum = forms.RegexField(
label=_("OCLCnum"),
regex=r'^\d\d\d\d\d\d\d\d\d*$',
required = False,
help_text = _("8 or more digits."),
error_messages = {
'invalid': _("This value must be 8 or more digits."),
}
)
language = forms.ChoiceField(choices=LANGUAGES) language = forms.ChoiceField(choices=LANGUAGES)
description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 2})) description = forms.CharField( required=False, widget= forms.Textarea(attrs={'cols': 80, 'rows': 2}))
class Meta: class Meta:

View File

@ -101,7 +101,7 @@
{% block news %} {% block news %}
<div class="launch_top"> <div class="launch_top">
It's here: our first unglued edition. You can now <a href="/work/81724/">download <I>Oral Literature in Africa</I></a>.<br /><br />Campaigns to unglue more books <a href="http://blog.unglue.it/2012/09/13/update-on-unglue-it-relaunch/">will relaunch soon</a>. It's here: our first unglued edition. You can now download <a href="/work/81724/"><I>Oral Literature in Africa</I></a>.<br /><br />Campaigns to unglue more books <a href="http://blog.unglue.it/2012/09/13/update-on-unglue-it-relaunch/">will relaunch soon</a>.
</div> </div>
{% endblock %} {% endblock %}

View File

@ -19,13 +19,13 @@
<h3>Read the unglued edition!</h3> <h3>Read the unglued edition!</h3>
<div class="ebook_download"> <div class="ebook_download">
{% for ebook in unglued_ebooks %} {% for ebook in unglued_ebooks %}
{% with ebook.url as url %} <a href="{{ ebook.url }}">
<a href="{{ url }}"><img src="{{ ebook.rights_badge }}"></a> <img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{{ url }}">{{ ebook.format }}</a> <a href="{{ ebook.url }}"><img src="/static/images/{{ ebook.format }}32.png" height="32" alt="{{ ebook.format }}" title="{{ ebook.format }}" /></a>
<a href="{{ ebook.url }}">{{ ebook.format }}</a>
{% ifequal ebook.format 'mobi' %} (use for Kindle){% endifequal %} {% ifequal ebook.format 'mobi' %} (use for Kindle){% endifequal %}
{% ifequal ebook.format 'epub' %} (use for Nook, Apple, Sony){% endifequal %} {% ifequal ebook.format 'epub' %} (use for Nook, Apple, Sony){% endifequal %}
{% if not forloop.last %}<br /><br />{% endif %} {% if not forloop.last %}<br /><br />{% endif %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -38,13 +38,13 @@
<h4>Freely available editions</h4> <h4>Freely available editions</h4>
{% endif %} {% endif %}
{% for ebook in other_ebooks %} {% for ebook in other_ebooks %}
{% with ebook.url as url %} <a href="{{ ebook.url }}">
<a href="{{ url }}"><img src="{{ ebook.rights_badge }}"></a> <img src="{{ ebook.rights_badge }}" alt="{{ ebook.rights}}" title="{{ ebook.rights}}" /></a>
<a href="{{ url }}">{{ ebook.format }}</a> <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}}" /></a>
<a href="{{ ebook.url }}">{{ ebook.format }} at {{ebook.provider}}</a>
{% ifequal ebook.format 'mobi' %} (use for Kindle){% endifequal %} {% ifequal ebook.format 'mobi' %} (use for Kindle){% endifequal %}
{% ifequal ebook.format 'epub' %} (use for Nook, Apple, Sony){% endifequal %} {% ifequal ebook.format 'epub' %} (use for Nook, Apple, Sony){% endifequal %}
{% if not forloop.last %}<br /><br />{% endif %} {% if not forloop.last %}<br /><br />{% endif %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
@ -59,13 +59,13 @@
<p>If this doesn't work, use the instructions below for your device.</p> <p>If this doesn't work, use the instructions below for your device.</p>
{% if unglued_epub_url %} {% if readmill_epub_url %}
<h4>Readmill users</h4> <h4>Readmill users</h4>
<p>If you're a <a href="http://readmill.com/">Readmill</a> member, you can send unglued ebooks to your iPad with one click. Here you go:</p> <p>If you're a <a href="http://readmill.com/">Readmill</a> member, you can send unglued ebooks to your iPad with one click. Here you go:</p>
<div class="send-to-readmill" data-download-url="{{ unglued_epub_url }}" data-buy-url="{{ base_url }}{% url work work.id %}" data-display="small" onload="/static/js/readmill.js"></div> <div class="send-to-readmill" data-download-url="{{ readmill_epub_url }}" data-buy-url="{{ base_url }}{% url work work.id %}" data-display="small"></div>
{% endif %} {% endif %}
<h4>Android devices</h4> <h4>Android devices</h4>
<p class="ebook_download logo"><img src="/static/images/aldiko_logo.png">Aldiko</p> <p class="ebook_download logo"><img src="/static/images/aldiko_logo.png" alt="Aldiko Logo" />Aldiko</p>
<ul> <ul>
<li><a href="http://www.aldiko.com/download.html">Download the free Aldiko app.</a></li> <li><a href="http://www.aldiko.com/download.html">Download the free Aldiko app.</a></li>
@ -77,7 +77,7 @@
{% endcomment %} {% endcomment %}
<h4>iOS devices</h4> <h4>iOS devices</h4>
<p class="ebook_download logo"><img src="/static/images/ibooks_logo.jpeg">iBooks</p> <p class="ebook_download logo"><img src="/static/images/ibooks_logo.jpeg" alt="iBooks Logo" />iBooks</p>
{% comment %}test{% endcomment %} {% comment %}test{% endcomment %}
<ul> <ul>
<li><a href="http://itunes.apple.com/us/app/ibooks/id364709193?mt=8">Download the free iBooks app</a> from the App Store.</li> <li><a href="http://itunes.apple.com/us/app/ibooks/id364709193?mt=8">Download the free iBooks app</a> from the App Store.</li>
@ -86,7 +86,7 @@
</ul> </ul>
<h4>PC, Mac, or Linux</h4> <h4>PC, Mac, or Linux</h4>
<p class="ebook_download logo"><img src="/static/images/calibre_logo.png">Calibre</p> <p class="ebook_download logo"><img src="/static/images/calibre_logo.png" alt="Calibre Logo" />Calibre</p>
<ul> <ul>
<li><a href="http://calibre-ebook.com/download">Download the free Calibre app.</a></li> <li><a href="http://calibre-ebook.com/download">Download the free Calibre app.</a></li>
<li>Download your book from this page using your device's web browser.</li> <li>Download your book from this page using your device's web browser.</li>

View File

@ -46,6 +46,7 @@
<p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p> <p><b>Language</b>: {{ form.language.errors }}{{ form.language }}</p>
<p><b>ISBN-13</b>: {{ form.isbn_13.errors }}{{ form.isbn_13 }}</p> <p><b>ISBN-13</b>: {{ form.isbn_13.errors }}{{ form.isbn_13 }}</p>
<p><b>OCLC Number</b>: {{ form.oclcnum.errors }}{{ form.oclcnum }}</p>
<p><b>Description</b>: <br /> <p><b>Description</b>: <br />
{{ form.description.errors }}{{ form.description }}<br /> {{ form.description.errors }}{{ form.description }}<br />

View File

@ -14,7 +14,6 @@
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script> <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
<script type="text/javascript" src="/static/js/counter.js"></script> <script type="text/javascript" src="/static/js/counter.js"></script>
<script type="text/javascript" src="/static/js/embed.js"></script> <script type="text/javascript" src="/static/js/embed.js"></script>
<script type="text/javascript" src="/static/js/readmill.js"></script>
<script> <script>
var $j = jQuery.noConflict(); var $j = jQuery.noConflict();
@ -153,6 +152,9 @@ $j(document).ready(function(){
{% if work.googlebooks_id %} {% if work.googlebooks_id %}
<a id="find-google" href="{{ work.googlebooks_url }}"><img src="/static/images/supporter_icons/googlebooks_square.png" title="Find on Google Books" alt="Find on Google Books" /></a> <a id="find-google" href="{{ work.googlebooks_url }}"><img src="/static/images/supporter_icons/googlebooks_square.png" title="Find on Google Books" alt="Find on Google Books" /></a>
{% endif %} {% endif %}
{% if work.first_oclc %}
<a rel="nofollow" id="find-oclc" href="http://www.worldcat.org/oclc/{{ work.first_oclc }}"><img src="/static/images/supporter_icons/worldcat_square.png" title="Find on Worldcat" alt="Find on Worldcat" /></a>
{% endif %}
<a rel="nofollow" class="find-openlibrary" href="{% url work_openlibrary work_id %}"><img src="/static/images/supporter_icons/openlibrary_square.png" title="Find on OpenLibrary" alt="Find on OpenLibrary" /></a> <a rel="nofollow" class="find-openlibrary" href="{% url work_openlibrary work_id %}"><img src="/static/images/supporter_icons/openlibrary_square.png" title="Find on OpenLibrary" alt="Find on OpenLibrary" /></a>
{% if not request.user.is_anonymous %} {% if not request.user.is_anonymous %}
{% if request.user.profile.goodreads_user_link %} {% if request.user.profile.goodreads_user_link %}

View File

@ -324,7 +324,13 @@ def new_edition(request, work_id, edition_id, by=None):
work.description=form.cleaned_data['description'] work.description=form.cleaned_data['description']
work.title=form.cleaned_data['title'] work.title=form.cleaned_data['title']
work.save() work.save()
models.Identifier.get_or_add(type='isbn', value=form.cleaned_data['isbn_13'], edition=edition, work=work)
# note: this is very powerful. it can steal an isbn from another edition/work, and it will wipe the changed isbn from the db
models.Identifier.set(type='isbn', value=form.cleaned_data['isbn_13'], edition=edition, work=work)
if form.cleaned_data['oclcnum']:
# note: this is very powerful.(same comment as for isbn) use with care!
models.Identifier.set(type='oclc', value=form.cleaned_data['oclcnum'], edition=edition, work=work)
for author_name in edition.new_author_names: for author_name in edition.new_author_names:
try: try:
author= models.Author.objects.get(name=author_name) author= models.Author.objects.get(name=author_name)
@ -343,6 +349,7 @@ def new_edition(request, work_id, edition_id, by=None):
form = EditionForm(instance=edition, initial={ form = EditionForm(instance=edition, initial={
'language':language, 'language':language,
'isbn_13':edition.isbn_13, 'isbn_13':edition.isbn_13,
'oclcnum':edition.oclc,
'description':description, 'description':description,
'title': title 'title': title
}) })
@ -2016,12 +2023,15 @@ def download(request, work_id):
unglued_ebooks = work.ebooks().filter(edition__unglued=True) unglued_ebooks = work.ebooks().filter(edition__unglued=True)
other_ebooks = work.ebooks().filter(edition__unglued=False) other_ebooks = work.ebooks().filter(edition__unglued=False)
unglued_epub_url = work.ebooks().filter(format='epub')[0].url if work.ebooks().filter(format='epub').count() else None try:
readmill_epub_url = work.ebooks().filter(format='epub').exclude(provider='Google Books')[0].url
except:
readmill_epub_url = None
context.update({ context.update({
'unglued_ebooks': unglued_ebooks, 'unglued_ebooks': unglued_ebooks,
'other_ebooks': other_ebooks, 'other_ebooks': other_ebooks,
'unglued_epub_url': unglued_epub_url, 'readmill_epub_url': readmill_epub_url,
'base_url': settings.BASE_URL 'base_url': settings.BASE_URL
}) })

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -9,7 +9,7 @@ $j(document).ready(function() {
$j("#lightbox").load( $j(this).attr("href") + " #lightbox_content"); $j("#lightbox").load( $j(this).attr("href") + " #lightbox_content");
if ($j(this).attr("href").substr(-9,8) == "download") { if ($j(this).attr("href").substr(-9,8) == "download") {
jQuery.getScript('/static/js/readmill.js'); jQuery.getScript('https://platform.readmill.com/send.js');
} }
// fade-out rest of page elements on expand // fade-out rest of page elements on expand