From 292be7b4adfea60105ba78d74ace7425eb7a4284 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 24 Apr 2020 18:52:17 +0200 Subject: [PATCH] Fixes #4001: TOC contains parent books, and add links to previous and next book. --- src/catalogue/models/book.py | 35 ++++++++++++++ .../templates/catalogue/book_text.html | 47 +++++++++++++++++-- src/catalogue/utils.py | 6 +++ src/wolnelektury/static/css/master.book.css | 14 +++--- src/wolnelektury/static/css/new.book.css | 15 +++--- src/wolnelektury/static/js/book.js | 4 -- src/wolnelektury/static/js/book_text/toc.js | 14 ++++-- .../static/scss/book_text/box.scss | 3 +- 8 files changed, 112 insertions(+), 26 deletions(-) diff --git a/src/catalogue/models/book.py b/src/catalogue/models/book.py index 371bb3e2d..8b5ac637f 100644 --- a/src/catalogue/models/book.py +++ b/src/catalogue/models/book.py @@ -247,6 +247,41 @@ class Book(models.Model): def gallery_url(self): return gallery_url(self.slug) + def get_first_text(self): + if self.html_file: + return self + child = self.children.all().order_by('parent_number').first() + if child is not None: + return child.get_first_text() + + def get_last_text(self): + if self.html_file: + return self + child = self.children.all().order_by('parent_number').last() + if child is not None: + return child.get_last_text() + + def get_prev_text(self): + if not self.parent: + return None + 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() + return self.parent.get_prev_text() + + def get_next_text(self): + if not self.parent: + return None + sibling = self.parent.children.filter(parent_number__gt=self.parent_number).order_by('parent_number').first() + if sibling is not None: + return sibling.get_first_text() + return self.parent.get_next_text() + + def get_siblings(self): + if not self.parent: + return [] + return self.parent.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 c0fe955dd..4ff3d5ef4 100644 --- a/src/catalogue/templates/catalogue/book_text.html +++ b/src/catalogue/templates/catalogue/book_text.html @@ -28,7 +28,7 @@ {% endif %} @@ -62,9 +62,19 @@ {% block big-pane %}
- {{ book_text|safe }} + {% with next=book.get_next_text prev=book.get_prev_text %} + {% if next %} + {{ next.title }} → + {% endif %} + {% if prev %} + ← {{ prev.title }} + {% endif %} + {{ book_text|safe }} + {% endwith %}
+ +
{% trans "Close" %}
{% trans "Please wait..." %}
@@ -72,8 +82,39 @@
{% endblock big-pane %} - {% block footer %} +
+ {% if book.parent %} + {% for b in book.ancestor.all %} + {% if forloop.counter > 1 %} +
  • + {% endif %} + {{ b.title }} +
      + {% endfor %} + {% for b in book.get_siblings %} +
    1. + {% if b == book %} + {{ b.title }} +
      + {% else %} + {{ b.title }} + {% endif %} +
    2. + {% endfor %} + + {% for b in book.ancestor.all %} +
    + {% if not forloop.counter.last %} +
  • + {% endif %} + {% endfor %} + {% else %} + {{ book.title }} +
    + {% endif %} +
    +
    {% book_info book %}
    diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index d17ead0e6..d05657978 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -313,3 +313,9 @@ def gallery_url(slug): def get_mp3_length(path): from mutagen.mp3 import MP3 return int(MP3(path).info.length) + + +def set_file_permissions(self, fieldfile): + if fieldfile.instance.preview: + fieldfile.set_readable(False) + diff --git a/src/wolnelektury/static/css/master.book.css b/src/wolnelektury/static/css/master.book.css index 29d115b96..c430a69f5 100644 --- a/src/wolnelektury/static/css/master.book.css +++ b/src/wolnelektury/static/css/master.book.css @@ -95,7 +95,7 @@ img { } -#toc, #themes, #nota_red, #info, #other-versions, #objects { +#wltoc, #themes, #nota_red, #info, #other-versions, #objects { position: fixed; left: 0; top: 1.5em; @@ -128,30 +128,30 @@ img { z-index: 99; } -#toc ol, #themes ol, #objects ol { +#wltoc ol, #themes ol, #objects ol { list-style: none; padding: 0; margin: 0; } -#toc ol li { +#wltoc ol li { font-weight: bold; } -#toc ol ol { +#wltoc ol ol { padding: 0 0 1.5em 1.5em; margin: 0; } -#toc ol ol li { +#wltoc ol ol li { font-weight: normal; } -#toc h2 { +#wltoc h2 { display: none; } -#toc .anchor { +#wltoc .anchor { float: none; margin: 0; color: blue; diff --git a/src/wolnelektury/static/css/new.book.css b/src/wolnelektury/static/css/new.book.css index 689d99fee..2208cd342 100644 --- a/src/wolnelektury/static/css/new.book.css +++ b/src/wolnelektury/static/css/new.book.css @@ -24,30 +24,29 @@ img { /* ================================== */ /* = Header with logo and menu = */ /* ================================== */ -#toc ol, #themes ol, #objects ol { +#wltoc ol, #themes ol, #objects ol { list-style: none; padding: 0; margin: 0; } - -#toc ol li { - font-weight: bold; +#wltoc ol { + padding-left: 1.5em; } -#toc ol ol { +#wltoc ol ol { padding: 0 0 1.5em 1.5em; margin: 0; } -#toc ol ol li { +#wltoc ol ol li { font-weight: normal; } -#toc h2 { +#wltoc h2 { display: none; } -#toc .anchor { +#wltoc .anchor { float: none; margin: 0; color: blue; diff --git a/src/wolnelektury/static/js/book.js b/src/wolnelektury/static/js/book.js index 72d8174fc..dfb23162b 100644 --- a/src/wolnelektury/static/js/book.js +++ b/src/wolnelektury/static/js/book.js @@ -15,10 +15,6 @@ $(function() { } $.highlightFade.defaults.speed = 3000; - $('#toc').hide(); - if ($('#toc li').length == 0) { - $('#menu li a[href="#toc"]').remove(); - } if ($('#themes li').length == 0) { $('#menu li a[href="#themes"]').remove(); } diff --git a/src/wolnelektury/static/js/book_text/toc.js b/src/wolnelektury/static/js/book_text/toc.js index 31f4e9ffc..d03bbb9bd 100644 --- a/src/wolnelektury/static/js/book_text/toc.js +++ b/src/wolnelektury/static/js/book_text/toc.js @@ -1,9 +1,17 @@ (function($){$(function(){ + if ($("#toc a").length > 0) { + $("#toc > ol").appendTo($("#heretoc")); + } -if ($('#toc li').length > 0) { - $('#menu-toc').show(); -} + if ($('#wltoc li').length > 0) { + $('#menu-toc').show(); + } + if ($('#wltoc li a').length == 0) { + $('#menu li a[href="#wltoc"]').remove(); + } + + $("#toc").remove(); })})(jQuery); diff --git a/src/wolnelektury/static/scss/book_text/box.scss b/src/wolnelektury/static/scss/book_text/box.scss index 7a0423418..4b2211da8 100644 --- a/src/wolnelektury/static/scss/book_text/box.scss +++ b/src/wolnelektury/static/scss/book_text/box.scss @@ -11,8 +11,9 @@ the hidden boxes (TOC and Themes). top: 0; right: 0; + box-sizing: border-box; max-height: 100%; - @include size(max-width, 380px); + @include size(max-width, 400px); @include size(padding, 10px 10px 30px 10px); margin: 0; overflow-x: hidden; -- 2.20.1