- if not gallery and not objects and len(tags) == 1:
- tag = tags[0]
- if (tag.category in ('theme', 'thing') and PictureArea.tagged.with_any([tag]).exists() or
- Picture.tagged.with_any([tag]).exists()):
- return redirect('tagged_object_list_gallery', raw_tags, permanent=False)
-
- return render_to_response(
- 'catalogue/tagged_object_list.html',
- {
- 'object_list': objects,
- 'categories': categories,
- 'only_shelf': only_shelf,
- 'only_my_shelf': only_my_shelf,
- 'formats_form': forms.DownloadFormatsForm(),
- 'tags': tags,
- 'tag_ids': tags_pks,
- 'theme_is_set': theme_is_set,
- 'best': best,
- 'gallery': gallery,
- },
- context_instance=RequestContext(request))
-
-
-def book_fragments(request, slug, theme_slug):
- book = get_object_or_404(models.Book, slug=slug)
- theme = get_object_or_404(models.Tag, slug=theme_slug, category='theme')
- fragments = models.Fragment.tagged.with_all([theme]).filter(
- Q(book=book) | Q(book__ancestor=book))
-
- return render_to_response('catalogue/book_fragments.html', {
- 'book': book,
- 'theme': theme,
- 'fragments': fragments,
- }, context_instance=RequestContext(request))
-
-
-def book_detail(request, slug):
- try:
- book = models.Book.objects.get(slug=slug)
- except models.Book.DoesNotExist:
- return pdcounter_views.book_stub_detail(request, slug)
-
- return render_to_response('catalogue/book_detail.html', {
- 'book': book,
- 'tags': book.tags.exclude(category__in=('set', 'theme')),
- 'book_children': book.children.all().order_by('parent_number', 'sort_key'),
- }, 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 tylko do audiobook_tree, które jest używane tylko w snippets/audiobook_list.html, które nie jest używane
-def player(request, slug):
- book = get_object_or_404(models.Book, slug=slug)
- if not book.has_media('mp3'):
- raise Http404
-
- audiobooks, projects, have_oggs = get_audiobooks(book)
-
- # extra_info = book.extra_info
-
- return render_to_response('catalogue/player.html', {
- 'book': book,
- 'audiobook': '',
- 'audiobooks': audiobooks,
- 'projects': projects,
- }, context_instance=RequestContext(request))
-
-
-def book_text(request, slug):
- book = get_object_or_404(models.Book, slug=slug)
-
- if not book.has_html_file():
- raise Http404
- return render_to_response('catalogue/book_text.html', {'book': book,}, context_instance=RequestContext(request))
-
-
-# ==========
-# = Search =
-# ==========
-
-def _no_diacritics_regexp(query):
- """ returns a regexp for searching for a query without diacritics
-
- should be locale-aware """
- names = {
- u'a': u'aąĄ', u'c': u'cćĆ', u'e': u'eęĘ', u'l': u'lłŁ', u'n': u'nńŃ', u'o': u'oóÓ', u's': u'sśŚ',
- u'z': u'zźżŹŻ',
- u'ą': u'ąĄ', u'ć': u'ćĆ', u'ę': u'ęĘ', u'ł': u'łŁ', u'ń': u'ńŃ', u'ó': u'óÓ', u'ś': u'śŚ', u'ź': u'źŹ',
- u'ż': u'żŻ'
- }
-
- def repl(m):
- l = m.group()
- return u"(%s)" % '|'.join(names[l])
-
- return re.sub(u'[%s]' % (u''.join(names.keys())), repl, query)