From 13f2f447ee06e5a95b86ee6d027b17d209518fdd Mon Sep 17 00:00:00 2001 From: Radek Czajka <rczajka@rczajka.pl> Date: Thu, 27 Jan 2022 14:50:12 +0100 Subject: [PATCH] Fixes --- src/catalogue/models/book.py | 11 +++++++++++ src/catalogue/templates/catalogue/book_text.html | 7 ++++++- .../templates/catalogue/search_multiple_hits.html | 3 ++- src/search/index.py | 5 ++++- src/search/views.py | 15 +++++++++------ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index b1684f930..1be9a9f3c 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -268,9 +268,17 @@ class Book(models.Model): sibling = self.parent.children.filter(parent_number__lt=self.parent_number).order_by('-parent_number').first() if sibling is not None: return sibling.get_last_text() + + if self.parent.html_file: + return self.parent + return self.parent.get_prev_text() def get_next_text(self): + child = self.children.order_by('parent_number').first() + if child is not None: + return child.get_first_text() + if not self.parent: return None sibling = self.parent.children.filter(parent_number__gt=self.parent_number).order_by('parent_number').first() @@ -283,6 +291,9 @@ class Book(models.Model): return [] return self.parent.children.all().order_by('parent_number') + def get_children(self): + return self.children.all().order_by('parent_number') + @property def name(self): return self.title diff --git a/src/catalogue/templates/catalogue/book_text.html b/src/catalogue/templates/catalogue/book_text.html index 17c4896b5..158396fe9 100644 --- a/src/catalogue/templates/catalogue/book_text.html +++ b/src/catalogue/templates/catalogue/book_text.html @@ -118,7 +118,7 @@ {% if forloop.counter > 1 %} <li> {% endif %} - <a href="{{ b.get_absolute_url }}">{{ b.title }}</a> + <a href="{% if b.html_file %}{% url 'book_text' b.slug %}{% else %}{{ b.get_absolute_url }}{% endif %}">{{ b.title }}</a> <ol> {% endfor %} {% for b in book.get_siblings %} @@ -141,6 +141,11 @@ {% else %} <strong>{{ book.title }}</strong> <div id="heretoc"></div> + <ol> + {% for c in book.get_children %} + <li><a href="{% url 'book_text' c.get_first_text.slug %}">{{ c.title }}</a></li> + {% endfor %} + </ol> {% endif %} </div> diff --git a/src/catalogue/templates/catalogue/search_multiple_hits.html b/src/catalogue/templates/catalogue/search_multiple_hits.html index 137175d80..937b9266d 100644 --- a/src/catalogue/templates/catalogue/search_multiple_hits.html +++ b/src/catalogue/templates/catalogue/search_multiple_hits.html @@ -19,7 +19,7 @@ <strong>format:</strong> {% if not set.format %}<em>dowolny</em>{% else %}<a href="{% set_get_parameter format='' %}">dowolny</a>{% endif %} {% if set.format == "tekst" %}<em>tekst</em>{% else %}<a href="{% set_get_parameter format='tekst' %}">tekst</a>{% endif %} - {% if set.format == "audio" %}<em>audiobook</em>{% else %}<a href="{% set_get_parameter format='audio' %}">tekst</a>{% endif %} + {% if set.format == "audio" %}<em>audiobook</em>{% else %}<a href="{% set_get_parameter format='audio' %}">audiobook</a>{% endif %} {% if set.format == "synchro" %}<em>DAISY</em>{% else %}<a href="{% set_get_parameter format='synchro' %}">DAISY</a>{% endif %} {% if set.format == "obraz" %}<em>obraz</em>{% else %}<a href="{% set_get_parameter format='obraz' %}">obraz</a>{% endif %} </p> @@ -38,6 +38,7 @@ <p class="search-filter"> <strong>{% trans "epoch" %}: </strong> {% if not set.epoch %}<em>dowolna</em>{% else %}<a href="{% set_get_parameter epoch='' %}">dowolna</a>{% endif %} + {% for tag in tags.epoch %} {% if set.epoch == tag.slug %} <em>{{ tag.name }}</em> diff --git a/src/search/index.py b/src/search/index.py index 06d2c4a6e..2be60fdf7 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -95,7 +95,10 @@ class Snippets(object): of the snippet stored there. """ self.file.seek(pos[0], 0) - txt = self.file.read(pos[1]).decode('utf-8') + try: + txt = self.file.read(pos[1]).decode('utf-8') + except: + return '' return txt def close(self): diff --git a/src/search/views.py b/src/search/views.py index e06b1cc48..b6e290b87 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -189,9 +189,9 @@ def main(request): 'genre': genre, }, 'tags': { - 'epoch': Tag.objects.filter(category='epoch'), - 'genre': Tag.objects.filter(category='genre'), - 'kind': Tag.objects.filter(category='kind'), + 'epoch': Tag.objects.filter(category='epoch', for_books=True), + 'genre': Tag.objects.filter(category='genre', for_books=True), + 'kind': Tag.objects.filter(category='kind', for_books=True), }, }) @@ -227,11 +227,11 @@ def search_books(query, lang=None, only_audio=False, only_synchro=False, epoch=N def ensure_exists(r): try: - r.book + if not r.book: + return False except Book.DoesNotExist: return False - print(lang, r.book.language) if lang and r.book.language != lang: return False if only_audio and not r.book.has_mp3_file(): @@ -278,7 +278,8 @@ def search_pictures(query, epoch=None, kind=None, genre=None): def ensure_exists(r): try: - return r.picture + if not r.picture: + return False except Picture.DoesNotExist: return False @@ -289,6 +290,8 @@ def search_pictures(query, epoch=None, kind=None, genre=None): if genre and not r.picture.tags.filter(category='genre', slug=genre).exists(): return False + return True + results = [r for r in results if ensure_exists(r)] return results -- 2.20.1