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()
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
{% 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 %}
{% 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>
<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>
<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>
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):
'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),
},
})
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():
def ensure_exists(r):
try:
- return r.picture
+ if not r.picture:
+ return False
except Picture.DoesNotExist:
return False
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