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)
28 vals = book_wide(context, book)
31 # for hit in result.hits:
33 # snippets.append(hit['snippets'])
34 # elif hit['fragment']:
35 # snippets.append(hit['fragment'].short_text)
37 # We don't need hits which lead to sections but do not have
39 vals['hits'] = filter(lambda h: 'fragment' in h or
40 h['snippets'], result.hits)
42 for hit in vals['hits']:
43 hit['snippets'] = map(lambda s: s.replace("\n", "<br />").replace('---', '—'), hit['snippets'])