From 90601de87f9fc5bf8addc74759d1e42ce61b0928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Farka?= <stepanfarka11@gmail.com> Date: Wed, 31 Aug 2022 15:23:41 +0200 Subject: [PATCH] [FIX] button if no next --- main/models.py | 4 ++-- main/templates/main/blocks/twitter_block.html | 2 +- main/templates/main/main_articles_page.html | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/main/models.py b/main/models.py index 0da3dbd68..6d511de27 100644 --- a/main/models.py +++ b/main/models.py @@ -218,7 +218,7 @@ class MainHomePage( ).content data = { "html": html_content.decode("utf-8"), - "last_page": tweet_page.paginator.num_pages, + "has_next": tweet_page.has_next(), } return JsonResponse(data=data, safe=False) @@ -388,7 +388,7 @@ class MainArticlesPage( ).content data = { "html": html_content.decode("utf-8"), - "last_page": article_page.paginator.num_pages, + "has_next": article_page.has_next(), } return JsonResponse(data=data, safe=False) diff --git a/main/templates/main/blocks/twitter_block.html b/main/templates/main/blocks/twitter_block.html index acd9f668a..c6e609aac 100644 --- a/main/templates/main/blocks/twitter_block.html +++ b/main/templates/main/blocks/twitter_block.html @@ -42,7 +42,7 @@ const data = await response.json() tweetsList.innerHTML += data.html; - if (btn.getAttribute('data-page') === data.last_page) { btn.hide() } + if (!data.has_next) { btn.style.display = 'none'; } const dataPage = parseInt(btn.getAttribute('data-page')) + 1 btn.setAttribute('data-page', dataPage) diff --git a/main/templates/main/main_articles_page.html b/main/templates/main/main_articles_page.html index ba40e551f..c61a8a35c 100644 --- a/main/templates/main/main_articles_page.html +++ b/main/templates/main/main_articles_page.html @@ -120,8 +120,7 @@ }) const data = await response.json() searchArticleResultWrapper.innerHTML += data.html; - if (btn.getAttribute('data-page') === data.last_page) - btn.hide(); + if (!data.has_next) { btn.style.display = 'none'; } btn.setAttribute('data-page', parseInt(btn.getAttribute('data-page')) + 1) } </script> -- GitLab