1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 from django import template
9 from django.template import Node, Variable
10 from django.utils.encoding import smart_str
11 from django.core.urlresolvers import reverse
12 # from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
13 # from django.db.models import Q
14 from django.conf import settings
15 # from django.utils.translation import ugettext as _
16 from catalogue.templatetags.catalogue_tags import book_wide
17 from catalogue.models import Book
18 # from catalogue.forms import SearchForm
19 # from catalogue.utils import split_tags
22 register = template.Library()
25 @register.inclusion_tag('catalogue/book_searched.html', takes_context=True)
26 def book_searched(context, result):
27 book = Book.objects.get(pk=result.book_id)
30 # for hit in result.hits:
32 # snippets.append(hit['snippets'])
33 # elif hit['fragment']:
34 # snippets.append(hit['fragment'].short_text)
36 # We don't need hits which lead to sections but do not have
38 hits = filter(lambda h: 'fragment' in h or
39 h['snippets'], result.hits)[0:5]
42 hit['snippets'] = map(lambda s: s.replace("\n", "<br />").replace('---', '—'), hit['snippets'])
45 'related': book.related_info(),
47 'main_link': book.get_absolute_url(),
48 'request': context.get('request'),
50 'main_link': book.get_absolute_url(),