From: Jan Szejko Date: Tue, 12 Dec 2017 16:28:24 +0000 (+0100) Subject: no ssi for book_short X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/dbdd1449a656f4c62055926d1531be95c2e6e66b no ssi for book_short --- diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index d8bc83212..02278de67 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -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.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 @@ -119,6 +119,9 @@ class Book(models.Model): 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') @@ -225,6 +228,33 @@ class Book(models.Model): 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 diff --git a/src/catalogue/templates/catalogue/book_searched.html b/src/catalogue/templates/catalogue/book_searched.html index 23d473689..06bb4fde0 100644 --- a/src/catalogue/templates/catalogue/book_searched.html +++ b/src/catalogue/templates/catalogue/book_searched.html @@ -2,9 +2,12 @@ {% load i18n %} {% load inline_tag_list from catalogue_tags %} {% load ssi_include from ssify %} + {% load cache %}
- {% ssi_include 'catalogue_book_short' pk=book.pk %} + {% cache 86400 catalogue_book_short book.pk %} + {% include 'catalogue/book_short.html' %} + {% endcache %}
{% for hit in hits %} diff --git a/src/catalogue/templates/catalogue/book_short.html b/src/catalogue/templates/catalogue/book_short.html index edd9f6b28..24d93d068 100644 --- a/src/catalogue/templates/catalogue/book_short.html +++ b/src/catalogue/templates/catalogue/book_short.html @@ -4,6 +4,8 @@ {% load book_shelf_tags from social_tags %} {% load static %} + {% with ga=book.get_audiobooks %} + {% with audiobooks=ga.0 %}
@@ -11,6 +13,7 @@ {% include "catalogue/snippets/like_button.html" %} {% endblock %} + {% with book.tags_by_category as tags %}
{% block book-box-body-pre %} @@ -20,11 +23,11 @@
{% for tag in tags.author %} {{ tag.name }}{% if not forloop.last %}, - {% endif %}{% endfor %}{% for parent in parents %}, + {% endif %}{% endfor %}{% for parent in book.parents %}, {{ parent.title }}{% endfor %}
{% if book.translator %}
@@ -35,9 +38,9 @@
{% if book.cover_thumb %} - {% if main_link %}{% endif %} + Cover - {% if main_link %}{% endif %} + {% endif %} {% block cover-area-extra %}{% endblock %}
@@ -67,7 +70,7 @@ {% endfor %} - {% if show_lang %} + {% if book.is_foreign %} {% trans "Language" %}:  {{ book.language_name }} @@ -75,12 +78,14 @@ {% endif %} - {% if stage_note %} + {% with stage_note=book.stage_note %} + {% if stage_note.0 %}
- {{ stage_note }} + {{ stage_note.0 }} {% endif %} + {% endwith %}
{% book_shelf_tags book.pk %} @@ -122,6 +127,7 @@ {% block box-append %} {% endblock %}
+ {% endwith %} {% block right-column %} {% if audiobooks %} @@ -134,4 +140,6 @@
+ {% endwith %} + {% endwith %} {% endspaceless %} diff --git a/src/catalogue/templates/catalogue/book_text.html b/src/catalogue/templates/catalogue/book_text.html index 629cb5bce..93e755f4d 100644 --- a/src/catalogue/templates/catalogue/book_text.html +++ b/src/catalogue/templates/catalogue/book_text.html @@ -110,6 +110,8 @@
- {% ssi_include 'catalogue_book_short' pk=book.pk %} + {% cache 86400 catalogue_book_short book.pk %} + {% include 'catalogue/book_short.html' %} + {% endcache %}
{% endblock footer %} diff --git a/src/catalogue/templates/catalogue/snippets/jplayer.html b/src/catalogue/templates/catalogue/snippets/jplayer.html index 860c2b6db..e3c88c14c 100644 --- a/src/catalogue/templates/catalogue/snippets/jplayer.html +++ b/src/catalogue/templates/catalogue/snippets/jplayer.html @@ -2,7 +2,7 @@ {% if audiobooks %}