no ssi for book_short
authorJan Szejko <janek37@gmail.com>
Tue, 12 Dec 2017 16:28:24 +0000 (17:28 +0100)
committerJan Szejko <janek37@gmail.com>
Tue, 12 Dec 2017 16:28:24 +0000 (17:28 +0100)
src/catalogue/models/book.py
src/catalogue/templates/catalogue/book_searched.html
src/catalogue/templates/catalogue/book_short.html
src/catalogue/templates/catalogue/book_text.html
src/catalogue/templates/catalogue/snippets/jplayer.html
src/catalogue/views.py

index d8bc832..02278de 100644 (file)
@@ -21,7 +21,7 @@ from newtagging import managers
 from catalogue import constants
 from catalogue.fields import EbookField
 from catalogue.models import Tag, Fragment, BookMedia
 from catalogue import constants
 from catalogue.fields import EbookField
 from catalogue.models import Tag, Fragment, BookMedia
-from catalogue.utils import create_zip, gallery_url, gallery_path
+from catalogue.utils import create_zip, gallery_url, gallery_path, split_tags
 from catalogue.models.tag import prefetched_relations
 from catalogue import app_settings
 from catalogue import tasks
 from catalogue.models.tag import prefetched_relations
 from catalogue import app_settings
 from catalogue import tasks
@@ -119,6 +119,9 @@ class Book(models.Model):
         else:
             return ', '.join(self.tags.filter(category=category).values_list('name', flat=True))
 
         else:
             return ', '.join(self.tags.filter(category=category).values_list('name', flat=True))
 
+    def tags_by_category(self):
+        return split_tags(self.tags.exclude(category__in=('set', 'theme')))
+
     def author_unicode(self):
         return self.tag_unicode('author')
 
     def author_unicode(self):
         return self.tag_unicode('author')
 
@@ -225,6 +228,33 @@ class Book(models.Model):
     has_daisy_file.short_description = 'DAISY'
     has_daisy_file.boolean = True
 
     has_daisy_file.short_description = 'DAISY'
     has_daisy_file.boolean = True
 
+    def get_audiobooks(self):
+        ogg_files = {}
+        for m in self.media.filter(type='ogg').order_by().iterator():
+            ogg_files[m.name] = m
+
+        audiobooks = []
+        projects = set()
+        for mp3 in self.media.filter(type='mp3').iterator():
+            # ogg files are always from the same project
+            meta = mp3.extra_info
+            project = meta.get('project')
+            if not project:
+                # temporary fallback
+                project = u'CzytamySłuchając'
+
+            projects.add((project, meta.get('funded_by', '')))
+
+            media = {'mp3': mp3}
+
+            ogg = ogg_files.get(mp3.name)
+            if ogg:
+                media['ogg'] = ogg
+            audiobooks.append(media)
+
+        projects = sorted(projects)
+        return audiobooks, projects
+
     def wldocument(self, parse_dublincore=True, inherit=True):
         from catalogue.import_utils import ORMDocProvider
         from librarian.parser import WLDocument
     def wldocument(self, parse_dublincore=True, inherit=True):
         from catalogue.import_utils import ORMDocProvider
         from librarian.parser import WLDocument
index 23d4736..06bb4fd 100644 (file)
@@ -2,9 +2,12 @@
   {% load i18n %}
   {% load inline_tag_list from catalogue_tags %}
   {% load ssi_include from ssify %}
   {% load i18n %}
   {% load inline_tag_list from catalogue_tags %}
   {% load ssi_include from ssify %}
+  {% load cache %}
 
   <div class="search-result">
 
   <div class="search-result">
-    {% ssi_include 'catalogue_book_short' pk=book.pk %}
+    {% cache 86400 catalogue_book_short book.pk %}
+      {% include 'catalogue/book_short.html' %}
+    {% endcache %}
 
     <div class="snippets">
       {% for hit in hits %}
 
     <div class="snippets">
       {% for hit in hits %}
index edd9f6b..24d93d0 100644 (file)
@@ -4,6 +4,8 @@
   {% load book_shelf_tags from social_tags %}
   {% load static %}
 
   {% load book_shelf_tags from social_tags %}
   {% load static %}
 
+  {% with ga=book.get_audiobooks %}
+  {% with audiobooks=ga.0 %}
   <div class="{% block box-class %}book-box{% if audiobooks %} audiobook-box{% endif %}{% endblock %}">
     <div class="book-box-inner">
 
   <div class="{% block box-class %}book-box{% if audiobooks %} audiobook-box{% endif %}{% endblock %}">
     <div class="book-box-inner">
 
@@ -11,6 +13,7 @@
       {% include "catalogue/snippets/like_button.html" %}
     {% endblock %}
 
       {% include "catalogue/snippets/like_button.html" %}
     {% endblock %}
 
+    {% with book.tags_by_category as tags %}
     <div class="book-left-column">
       <div class="book-box-body">
         {% block book-box-body-pre %}
     <div class="book-left-column">
       <div class="book-box-body">
         {% block book-box-body-pre %}
           <div class="author">
             {% for tag in tags.author %}
               <a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a>{% if not forloop.last %},
           <div class="author">
             {% for tag in tags.author %}
               <a href="{{ tag.get_absolute_url }}">{{ tag.name }}</a>{% if not forloop.last %},
-            {% endif %}{% endfor %}{% for parent in parents %},
+            {% endif %}{% endfor %}{% for parent in book.parents %},
               <a href="{{ parent.get_absolute_url }}">{{ parent.title }}</a>{% endfor %}
           </div>
           <div class="title">
               <a href="{{ parent.get_absolute_url }}">{{ parent.title }}</a>{% endfor %}
           </div>
           <div class="title">
-            {% if main_link %}<a href="{{ main_link }}">{% endif %}{{ book.title }}{% if main_link %}</a>{% endif %}
+            <a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
           </div>
           {% if book.translator %}
               <div class="author">
           </div>
           {% if book.translator %}
               <div class="author">
@@ -35,9 +38,9 @@
 
         <div class="cover-area">
           {% if book.cover_thumb %}
 
         <div class="cover-area">
           {% if book.cover_thumb %}
-            {% if main_link %}<a href="{{ main_link }}">{% endif %}
+            <a href="{{ book.get_absolute_url }}">
               <img src="{{ book.cover_thumb.url }}" alt="Cover" class="cover" />
               <img src="{{ book.cover_thumb.url }}" alt="Cover" class="cover" />
-            {% if main_link %}</a>{% endif %}
+            </a>
           {% endif %}
           {% block cover-area-extra %}{% endblock %}
         </div>
           {% endif %}
           {% block cover-area-extra %}{% endblock %}
         </div>
@@ -67,7 +70,7 @@
             {% endfor %}
           </span></span>
 
             {% endfor %}
           </span></span>
 
-          {% if show_lang %}
+          {% if book.is_foreign %}
             <span class="category">
               <span class="mono"> {% trans "Language" %}:</span>&nbsp;<span class="book-box-tag">
                 <a>{{ book.language_name }}</a>
             <span class="category">
               <span class="mono"> {% trans "Language" %}:</span>&nbsp;<span class="book-box-tag">
                 <a>{{ book.language_name }}</a>
             </span>
           {% endif %}
 
             </span>
           {% endif %}
 
-          {% if stage_note %}
+          {% with stage_note=book.stage_note %}
+          {% if stage_note.0 %}
             <br>
             <span class="category">
             <br>
             <span class="category">
-              <a{% if stage_note_url %} href="{{ stage_note_url }}"{% endif %}>{{ stage_note }}</a>
+              <a{% if stage_note.1 %} href="{{ stage_note.1 }}"{% endif %}>{{ stage_note.0 }}</a>
             </span>
           {% endif %}
             </span>
           {% endif %}
+          {% endwith %}
         </div>
       </div>
       {% book_shelf_tags book.pk %}
         </div>
       </div>
       {% book_shelf_tags book.pk %}
       {% block box-append %}
       {% endblock %}
     </div>
       {% block box-append %}
       {% endblock %}
     </div>
+    {% endwith %}
 
     {% block right-column %}
       {% if audiobooks %}
 
     {% block right-column %}
       {% if audiobooks %}
     <div class="clearboth"></div>
     </div>
   </div>
     <div class="clearboth"></div>
     </div>
   </div>
+  {% endwith %}
+  {% endwith %}
 {% endspaceless %}
 {% endspaceless %}
index 629cb5b..93e755f 100644 (file)
   </div>
 
   <div class="box" id="book-short">
   </div>
 
   <div class="box" id="book-short">
-    {% ssi_include 'catalogue_book_short' pk=book.pk %}
+    {% cache 86400 catalogue_book_short book.pk %}
+      {% include 'catalogue/book_short.html' %}
+    {% endcache %}
   </div>
 {% endblock footer %}
   </div>
 {% endblock footer %}
index 860c2b6..e3c88c1 100644 (file)
@@ -2,7 +2,7 @@
 {% if audiobooks %}
   <div class="jp-type-playlist">
     <div id="jplayer" class="jp-jplayer" data-player="jp_container_{{ book.pk }}"
 {% if audiobooks %}
   <div class="jp-type-playlist">
     <div id="jplayer" class="jp-jplayer" data-player="jp_container_{{ book.pk }}"
-         data-supplied="{% if have_oggs %}oga,{% endif %}mp3"></div>
+         data-supplied="oga,mp3"></div>
     <div id="jp_container_{{ book.pk }}" class="jp-audio">
       <div class="jp-type-single">
         <span class="title"></span>
     <div id="jp_container_{{ book.pk }}" class="jp-audio">
       <div class="jp-type-single">
         <span class="title"></span>
index 267d9b4..a247746 100644 (file)
@@ -286,44 +286,13 @@ def book_detail(request, slug):
     }, context_instance=RequestContext(request))
 
 
     }, context_instance=RequestContext(request))
 
 
-def get_audiobooks(book):
-    ogg_files = {}
-    for m in book.media.filter(type='ogg').order_by().iterator():
-        ogg_files[m.name] = m
-
-    audiobooks = []
-    have_oggs = True
-    projects = set()
-    for mp3 in book.media.filter(type='mp3').iterator():
-        # ogg files are always from the same project
-        meta = mp3.extra_info
-        project = meta.get('project')
-        if not project:
-            # temporary fallback
-            project = u'CzytamySłuchając'
-
-        projects.add((project, meta.get('funded_by', '')))
-
-        media = {'mp3': mp3}
-
-        ogg = ogg_files.get(mp3.name)
-        if ogg:
-            media['ogg'] = ogg
-        else:
-            have_oggs = False
-        audiobooks.append(media)
-
-    projects = sorted(projects)
-    return audiobooks, projects, have_oggs
-
-
 # używane w publicznym interfejsie
 def player(request, slug):
     book = get_object_or_404(Book, slug=slug)
     if not book.has_media('mp3'):
         raise Http404
 
 # używane w publicznym interfejsie
 def player(request, slug):
     book = get_object_or_404(Book, slug=slug)
     if not book.has_media('mp3'):
         raise Http404
 
-    audiobooks, projects, have_oggs = get_audiobooks(book)
+    audiobooks, projects = book.get_audiobooks()
 
     return render_to_response('catalogue/player.html', {
         'book': book,
 
     return render_to_response('catalogue/player.html', {
         'book': book,
@@ -672,20 +641,9 @@ def book_mini(request, pk, with_link=True):
     ))(ssi_expect(pk, int)))
 def book_short(request, pk):
     book = get_object_or_404(Book, pk=pk)
     ))(ssi_expect(pk, int)))
 def book_short(request, pk):
     book = get_object_or_404(Book, pk=pk)
-    stage_note, stage_note_url = book.stage_note()
-    audiobooks, projects, have_oggs = get_audiobooks(book)
 
     return render(request, 'catalogue/book_short.html', {
         'book': book,
 
     return render(request, 'catalogue/book_short.html', {
         'book': book,
-        'has_audio': book.has_media('mp3'),
-        'main_link': book.get_absolute_url(),
-        'parents': book.parents(),
-        'tags': split_tags(book.tags.exclude(category__in=('set', 'theme'))),
-        'show_lang': book.language_code() != settings.LANGUAGE_CODE,
-        'stage_note': stage_note,
-        'stage_note_url': stage_note_url,
-        'audiobooks': audiobooks,
-        'have_oggs': have_oggs,
     })
 
 
     })
 
 
@@ -698,24 +656,17 @@ def book_short(request, pk):
     ))(ssi_expect(pk, int)))
 def book_wide(request, pk):
     book = get_object_or_404(Book, pk=pk)
     ))(ssi_expect(pk, int)))
 def book_wide(request, pk):
     book = get_object_or_404(Book, pk=pk)
-    stage_note, stage_note_url = book.stage_note()
     extra_info = book.extra_info
     extra_info = book.extra_info
-    audiobooks, projects, have_oggs = get_audiobooks(book)
 
     return render(request, 'catalogue/book_wide.html', {
         'book': book,
 
     return render(request, 'catalogue/book_wide.html', {
         'book': book,
-        'has_audio': book.has_media('mp3'),
         'parents': book.parents(),
         'tags': split_tags(book.tags.exclude(category__in=('set', 'theme'))),
         'show_lang': book.language_code() != settings.LANGUAGE_CODE,
         'parents': book.parents(),
         'tags': split_tags(book.tags.exclude(category__in=('set', 'theme'))),
         'show_lang': book.language_code() != settings.LANGUAGE_CODE,
-        'stage_note': stage_note,
-        'stage_note_url': stage_note_url,
 
         'main_link': reverse('book_text', args=[book.slug]) if book.html_file else None,
         'extra_info': extra_info,
         'hide_about': extra_info.get('about', '').startswith('http://wiki.wolnepodreczniki.pl'),
 
         'main_link': reverse('book_text', args=[book.slug]) if book.html_file else None,
         'extra_info': extra_info,
         'hide_about': extra_info.get('about', '').startswith('http://wiki.wolnepodreczniki.pl'),
-        'audiobooks': audiobooks,
-        'have_oggs': have_oggs,
     })
 
 
     })