From: Radek Czajka Date: Thu, 27 Jan 2022 13:50:12 +0000 (+0100) Subject: Fixes X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/13f2f447ee06e5a95b86ee6d027b17d209518fdd Fixes --- 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 %}
  • {% endif %} - {{ b.title }} + {{ b.title }}
      {% endfor %} {% for b in book.get_siblings %} @@ -141,6 +141,11 @@ {% else %} {{ book.title }}
      +
        + {% for c in book.get_children %} +
      1. {{ c.title }}
      2. + {% endfor %} +
      {% endif %} 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 @@ format: {% if not set.format %}dowolny{% else %}dowolny{% endif %} {% if set.format == "tekst" %}tekst{% else %}tekst{% endif %} - {% if set.format == "audio" %}audiobook{% else %}tekst{% endif %} + {% if set.format == "audio" %}audiobook{% else %}audiobook{% endif %} {% if set.format == "synchro" %}DAISY{% else %}DAISY{% endif %} {% if set.format == "obraz" %}obraz{% else %}obraz{% endif %}

      @@ -38,6 +38,7 @@

      {% trans "epoch" %}: {% if not set.epoch %}dowolna{% else %}dowolna{% endif %} + {% for tag in tags.epoch %} {% if set.epoch == tag.slug %} {{ tag.name }} 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