hits = sections.values()
for f in frags:
- frag = catalogue.models.Fragment.objects.get(anchor=f[FRAGMENT])
+ try:
+ frag = catalogue.models.Fragment.objects.get(anchor=f[FRAGMENT])
+ except catalogue.models.Fragment.DoesNotExist:
+ # stale index
+ continue
# Figure out if we were searching for a token matching some word in theme name.
themes = frag.tags.filter(category='theme')
@register.inclusion_tag('catalogue/book_searched.html', takes_context=True)
def book_searched(context, result):
book = Book.objects.get(pk=result.book_id)
- vals = book_wide(context, book)
# snippets = []
# for hit in result.hits:
# We don't need hits which lead to sections but do not have
# snippets.
- vals['hits'] = filter(lambda h: 'fragment' in h or
- h['snippets'], result.hits)
+ hits = filter(lambda h: 'fragment' in h or
+ h['snippets'], result.hits)
- for hit in vals['hits']:
+ for hit in hits:
hit['snippets'] = map(lambda s: s.replace("\n", "<br />").replace('---', '—'), hit['snippets'])
- return vals
+ return {
+ 'related': book.related_info(),
+ 'book': book,
+ 'request': context.get('request'),
+ 'hits': hits,
+ }
{% extends "base.html" %}
{% load i18n %}
-{% load search_tags pagination_tags %}
+{% load catalogue_tags search_tags pagination_tags %}
{% block titleextra %}{% trans "Search" %}{% endblock %}
<ol class="work-list">
{% for author in results.author %}
<li class="work-item">
- {{author.book.short_html}}
+ {% book_short author.book %}
</li>
{% endfor %}
</ol>
<ol class="work-list">
{% for result in results.title %}
<li class="work-item">
- {{result.book.short_html}}
+ {% book_short result.book %}
</li>
{% endfor %}
</ol>