Fix hearts
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 11 Jun 2025 08:15:16 +0000 (10:15 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 11 Jun 2025 08:15:16 +0000 (10:15 +0200)
src/social/views.py
src/wolnelektury/static/js/book_text/progress.js
src/wolnelektury/static/js/book_text/references.js
src/wolnelektury/static/js/main.js

index 3dfcd9e..4aaf54e 100644 (file)
@@ -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):
index ae5b14a..723e03e 100644 (file)
@@ -4,6 +4,8 @@
 
     function upd_t() {
         $text = $('#main-text #book-text');
+        if (!$text.length) return;
+
         texttop = $text.offset().top;
 
         $footnotes = $('#footnotes', $text);
index fa4a35a..3f5b7e3 100644 (file)
     }
 
     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 © <a href="http://www.thunderforest.com">Thunderforest</a>, Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
         }).addTo(map);
+        marker = L.circleMarker([0,0]);
 
         map_enabled = true;
     }
index 2feb7b8..c82516b 100644 (file)
                 },
                 error: function(e) {
                     if (e.status == 403) {
-                        $('#login-link').click();
+                        window.location.href = $('#login-link').attr('href')
                     }
                 },
             });