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
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')
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
{% load i18n %}
{% load inline_tag_list from catalogue_tags %}
{% load ssi_include from ssify %}
+ {% load cache %}
<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 %}
{% 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">
{% 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="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">
- {% 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 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" />
- {% if main_link %}</a>{% endif %}
+ </a>
{% endif %}
{% block cover-area-extra %}{% endblock %}
</div>
{% endfor %}
</span></span>
- {% if show_lang %}
+ {% if book.is_foreign %}
<span class="category">
<span class="mono"> {% trans "Language" %}:</span> <span class="book-box-tag">
<a>{{ book.language_name }}</a>
</span>
{% endif %}
- {% if stage_note %}
+ {% with stage_note=book.stage_note %}
+ {% if stage_note.0 %}
<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 %}
+ {% endwith %}
</div>
</div>
{% book_shelf_tags book.pk %}
{% block box-append %}
{% endblock %}
</div>
+ {% endwith %}
{% block right-column %}
{% if audiobooks %}
<div class="clearboth"></div>
</div>
</div>
+ {% endwith %}
+ {% endwith %}
{% endspaceless %}
</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 %}
{% 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>
}, 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
- audiobooks, projects, have_oggs = get_audiobooks(book)
+ audiobooks, projects = book.get_audiobooks()
return render_to_response('catalogue/player.html', {
'book': book,
))(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,
- '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,
})
))(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
- audiobooks, projects, have_oggs = get_audiobooks(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,
- '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'),
- 'audiobooks': audiobooks,
- 'have_oggs': have_oggs,
})