fix #2036, fix #2078: more audiobook links
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 17 Apr 2012 14:22:06 +0000 (16:22 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 17 Apr 2012 14:22:06 +0000 (16:22 +0200)
apps/catalogue/static/player/openplayer.js [new file with mode: 0644]
apps/catalogue/static/player/player.css
apps/catalogue/templates/catalogue/book_text.html
apps/catalogue/templates/catalogue/book_wide.html
apps/catalogue/templates/catalogue/player.html
apps/catalogue/templatetags/catalogue_tags.py
apps/catalogue/views.py
apps/wolnelektury_core/static/js/base.js
wolnelektury/settings/static.py

diff --git a/apps/catalogue/static/player/openplayer.js b/apps/catalogue/static/player/openplayer.js
new file mode 100644 (file)
index 0000000..e8da79c
--- /dev/null
@@ -0,0 +1,18 @@
+(function($) {
+    $(function() {
+
+
+
+$('.open-player').click(function(event) {
+    event.preventDefault();
+    window.open($(this).attr('href'),
+        'player',
+        'width=422, height=500'
+        );
+});
+
+
+
+    });
+})(jQuery);
+
index c449803..829a9a1 100644 (file)
@@ -15,3 +15,7 @@
 .play:hover {
        color: #0D7E85;
 }
 .play:hover {
        color: #0D7E85;
 }
+
+.daisy-list {
+    list-style: none;
+}
index 53a0c6a..e844c96 100644 (file)
@@ -1,4 +1,5 @@
 {% load i18n %}
 {% load i18n %}
+{% load url from future %}
 {% load static from staticfiles %}
 {% load chunks compressed catalogue_tags %}
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 {% load static from staticfiles %}
 {% load chunks compressed catalogue_tags %}
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                 <li><a class="menu" href="#info">{% trans "Infobox" %}</a></li>
                 <li><a href="{{ book.get_absolute_url }}">{% trans "Book's page" %}</a></li>
                 <li><a class="menu" href="#download">{% trans "Download" %}</a></li>
                 <li><a class="menu" href="#info">{% trans "Infobox" %}</a></li>
                 <li><a href="{{ book.get_absolute_url }}">{% trans "Book's page" %}</a></li>
                 <li><a class="menu" href="#download">{% trans "Download" %}</a></li>
+                {% if related.media.mp3 or related.media.ogg %}
+                    <li><a class="open-player" target="_blank" href="{% url "book_player" book.slug %}">
+                        {% trans "Listen" %}</a></li>
+                {% endif %}
             </ul>
         </div>
         <div id="info">
             </ul>
         </div>
         <div id="info">
             {% if book.pdf_file %}
             <li><a href="{{ book.pdf_file.url}}">PDF</a> {% trans "to print" %}</li>
             {% endif %}
             {% if book.pdf_file %}
             <li><a href="{{ book.pdf_file.url}}">PDF</a> {% trans "to print" %}</li>
             {% endif %}
-            {% if  book.epub_file %}
+            {% if book.epub_file %}
             <li><a href="{{ book.epub_file.url}}">EPUB</a> {% trans "for a reader" %}</li>
             {% endif %}
             <li><a href="{{ book.epub_file.url}}">EPUB</a> {% trans "for a reader" %}</li>
             {% endif %}
-            {% if  book.mobi_file %}
+            {% if book.mobi_file %}
             <li><a href="{{ book.mobi_file.url}}">MOBI</a> {% trans "for Kindle" %}</li>
             {% endif %}
             <li><a href="{{ book.mobi_file.url}}">MOBI</a> {% trans "for Kindle" %}</li>
             {% endif %}
-            {% if  book.txt_file %}
+            {% if book.txt_file %}
             <li><a href="{{ book.txt_file.url}}">TXT</a> {% trans "for advanced usage" %}</li>
             {% endif %}
             <li><a href="{{ book.txt_file.url}}">TXT</a> {% trans "for advanced usage" %}</li>
             {% endif %}
-            <li><a href="{% url custom_pdf_form book.slug %}">{% trans "Download a custom PDF" %}</a></li>
+            <li><a href="{% url "custom_pdf_form" book.slug %}">{% trans "Download a custom PDF" %}</a></li>
+            {% if related.media.mp3 or related.media.ogg or related.media.daisy %}
+                <li>{% trans "Download all audiobooks for this book" %}:
+                    {% download_audio book %}</li> 
+            {% endif %}
             </ul>
         </div>
         <div id="header">
             </ul>
         </div>
         <div id="header">
index ad588bd..9213560 100644 (file)
@@ -1,6 +1,6 @@
 {% extends "catalogue/book_short.html" %}
 {% load i18n %}
 {% extends "catalogue/book_short.html" %}
 {% load i18n %}
-{% load tag_list from catalogue_tags %}
+{% load download_audio tag_list from catalogue_tags %}
 {% load cite_promo from social_tags %}
 
 
 {% load cite_promo from social_tags %}
 
 
     <h2 class="mono">{% trans "Download" %}</h2>
     <ul class="plain">
       <li>
     <h2 class="mono">{% trans "Download" %}</h2>
     <ul class="plain">
       <li>
-       {% if related.media.mp3 or related.media.ogg %}
-       {% trans "Download all audiobooks for this book" %}: 
-       {% if related.media.mp3 %}<a href="{% url download_zip_mp3 book.slug %}">MP3</a>{% endif %}{% if related.media.mp3 and related.media.ogg %},{% endif %}
-       {% if related.media.ogg %}<a href="{% url download_zip_ogg book.slug %}">OGG</a>{% endif %}.
+       {% if related.media.mp3 or related.media.ogg or related.media.daisy %}
+        {% trans "Download all audiobooks for this book" %}:
+           {% download_audio book %}. 
        {% endif %}
       </li>
       <li>
        {% endif %}
       </li>
       <li>
index 7ecf3e6..f32025b 100755 (executable)
@@ -1,5 +1,6 @@
 <!DOCTYPE html>
 <html>
 <!DOCTYPE html>
 <html>
+    {% load static from staticfiles %}
     {% load i18n compressed %}
     {% load catalogue_tags %}
     {% load thumbnail %}
     {% load i18n compressed %}
     {% load catalogue_tags %}
     {% load thumbnail %}
 
 <div class="player-info normal-text">
        <p><a target="_blank" href="{{ book.get_absolute_url }}">{% trans "Book's page" %}</a>.</p>
 
 <div class="player-info normal-text">
        <p><a target="_blank" href="{{ book.get_absolute_url }}">{% trans "Book's page" %}</a>.</p>
-       <p>{% trans "Download as" %}
-        <a href="{% url download_zip_mp3 book.slug %}">MP3</a>{% if have_oggs %},
-            <a href="{% url download_zip_ogg book.slug %}">Ogg Vorbis</a>{% endif %}.
-    </p>
+       <p>{% trans "Download as" %} {% download_audio book False %}.</p>
 
     {% if book.has_daisy_file %}
         <p>DAISY:</p>
 
     {% if book.has_daisy_file %}
         <p>DAISY:</p>
index 78ce04a..fdd0a73 100644 (file)
@@ -14,7 +14,7 @@ from django.utils.translation import ugettext as _
 
 from catalogue import forms
 from catalogue.utils import split_tags
 
 from catalogue import forms
 from catalogue.utils import split_tags
-from catalogue.models import Book, Fragment, Tag
+from catalogue.models import Book, BookMedia, Fragment, Tag
 
 register = template.Library()
 
 
 register = template.Library()
 
@@ -387,3 +387,22 @@ def tag_url(category, slug):
     return reverse('catalogue.views.tagged_object_list', args=[
         '/'.join((Tag.categories_dict[category], slug))
     ])
     return reverse('catalogue.views.tagged_object_list', args=[
         '/'.join((Tag.categories_dict[category], slug))
     ])
+
+
+@register.simple_tag
+def download_audio(book, daisy=True):
+    related = book.related_info()
+    links = []
+    if related['media'].get('mp3'):
+        links.append("<a href='%s'>%s</a>" %
+            (reverse('download_zip_mp3', args=[book.slug]),
+                BookMedia.formats['mp3'].name))
+    if related['media'].get('ogg'):
+        links.append("<a href='%s'>%s</a>" %
+            (reverse('download_zip_ogg', args=[book.slug]),
+                BookMedia.formats['ogg'].name))
+    if daisy and related['media'].get('daisy'):
+        for dsy in book.get_media('daisy'):
+            links.append("<a href='%s'>%s</a>" %
+                (dsy.file.url, BookMedia.formats['daisy'].name))
+    return ", ".join(links)
index 9687db6..599fde1 100644 (file)
@@ -265,6 +265,7 @@ def book_text(request, slug):
 
     book_themes = book_themes.items()
     book_themes.sort(key=lambda s: s[0].sort_key)
 
     book_themes = book_themes.items()
     book_themes.sort(key=lambda s: s[0].sort_key)
+    related = book.related_info()
     return render_to_response('catalogue/book_text.html', locals(),
         context_instance=RequestContext(request))
 
     return render_to_response('catalogue/book_text.html', locals(),
         context_instance=RequestContext(request))
 
index 77315e6..d43f1f2 100755 (executable)
@@ -97,15 +97,6 @@ $('#themes-list-toggle').click(function(event) {
 });
 
 
 });
 
 
-$('.open-player').click(function(event) {
-    event.preventDefault();
-    window.open($(this).attr('href'),
-        'player',
-        'width=422, height=500'
-        );
-});
-
-
         $('.book-list-index').click(function(){
             $('.book-list-show-index').hide('slow');
             if($(this).parent().next('ul:not(:hidden)').length == 0){
         $('.book-list-index').click(function(){
             $('.book-list-show-index').hide('slow');
             if($(this).parent().next('ul:not(:hidden)').length == 0){
index 8dcdf8f..e1e8594 100644 (file)
@@ -79,6 +79,7 @@ PIPELINE_JS = {
             'js/base.js',
             'pdcounter/pdcounter.js',
             'sponsors/js/sponsors.js',
             'js/base.js',
             'pdcounter/pdcounter.js',
             'sponsors/js/sponsors.js',
+            'player/openplayer.js',
 
             'js/search.js',
             ),
 
             'js/search.js',
             ),
@@ -93,7 +94,13 @@ PIPELINE_JS = {
         'output_filename': 'js/player.min.js',
     },
     'book': {
         'output_filename': 'js/player.min.js',
     },
     'book': {
-        'source_filenames': ('js/jquery.eventdelegation.js', 'js/jquery.scrollto.js', 'js/jquery.highlightfade.js', 'js/book.js',),
+        'source_filenames': [
+            'js/jquery.eventdelegation.js',
+            'js/jquery.scrollto.js',
+            'js/jquery.highlightfade.js',
+            'js/book.js',
+            'player/openplayer.js',
+        ],
         'output_filename': 'js/book.min.js',
     },
     'book_ie': {
         'output_filename': 'js/book.min.js',
     },
     'book_ie': {