From b89f3aa7efdc44a9b59b26384862df0f06803a7b Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 11 Jun 2025 10:15:16 +0200 Subject: [PATCH] Fix hearts --- src/social/views.py | 7 ++++--- src/wolnelektury/static/js/book_text/progress.js | 2 ++ src/wolnelektury/static/js/book_text/references.js | 5 ++++- src/wolnelektury/static/js/main.js | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/social/views.py b/src/social/views.py index 3dfcd9e2b..4aaf54e27 100644 --- a/src/social/views.py +++ b/src/social/views.py @@ -19,12 +19,13 @@ from wolnelektury.utils import is_ajax # ==================== -@require_POST +@login_required def like_book(request, slug): - if not request.user.is_authenticated: - return HttpResponseForbidden('Login required.') book = get_object_or_404(Book, slug=slug) + if request.method != 'POST': + return redirect(book.get_absolute_url()) + book.like(request.user) if is_ajax(request): diff --git a/src/wolnelektury/static/js/book_text/progress.js b/src/wolnelektury/static/js/book_text/progress.js index ae5b14ac4..723e03ec9 100644 --- a/src/wolnelektury/static/js/book_text/progress.js +++ b/src/wolnelektury/static/js/book_text/progress.js @@ -4,6 +4,8 @@ function upd_t() { $text = $('#main-text #book-text'); + if (!$text.length) return; + texttop = $text.offset().top; $footnotes = $('#footnotes', $text); diff --git a/src/wolnelektury/static/js/book_text/references.js b/src/wolnelektury/static/js/book_text/references.js index fa4a35a69..3f5b7e37f 100644 --- a/src/wolnelektury/static/js/book_text/references.js +++ b/src/wolnelektury/static/js/book_text/references.js @@ -10,10 +10,12 @@ } var map_enabled = false; - var marker = L.circleMarker([0,0]); + var marker = null; var map = null; function enable_map() { + if (!$("#reference-map").length) return; + $("#reference-map").show('slow'); if (map_enabled) return; @@ -22,6 +24,7 @@ L.tileLayer('https://tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=a8a97f0ae5134403ac38c1a075b03e15', { attribution: 'Maps © Thunderforest, Data © OpenStreetMap contributors' }).addTo(map); + marker = L.circleMarker([0,0]); map_enabled = true; } diff --git a/src/wolnelektury/static/js/main.js b/src/wolnelektury/static/js/main.js index 2feb7b8eb..c82516bf2 100644 --- a/src/wolnelektury/static/js/main.js +++ b/src/wolnelektury/static/js/main.js @@ -396,7 +396,7 @@ }, error: function(e) { if (e.status == 403) { - $('#login-link').click(); + window.location.href = $('#login-link').attr('href') } }, }); -- 2.20.1