From 0c5dffc5271e0c7842139cef8ebbd703ecbe93dc Mon Sep 17 00:00:00 2001 From: "oleg.vodyanov91@gmail.com" Date: Wed, 23 Apr 2025 15:33:32 +0400 Subject: [PATCH] fix --- instalinks/links/views.py | 7 +++---- static/links/main.js | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/instalinks/links/views.py b/instalinks/links/views.py index daec22c..5e2df5e 100644 --- a/instalinks/links/views.py +++ b/instalinks/links/views.py @@ -20,17 +20,16 @@ def links_list(request): try: page = int(request.GET.get('page', 1)) per_page = int(request.GET.get('per_page', 8)) - watched = bool(request.GET.get('watched', "")) + watched = bool(request.GET.get('watched', False)) except ValueError: return JsonResponse({'error': 'Invalid page or per_page'}, status=400) offset = (page - 1) * per_page limit = offset + per_page - all_links = Link.objects.all().order_by('-id') # latest first + all_links = Link.objects.get(watched__exact=watched).order_by('-id') # latest first total = all_links.count() - limit_results = list(all_links[offset:limit].values('id', 'url', 'watched')) - results = filter(lambda row: row['watched'] == str(watched), limit_results) + results = list(all_links[offset:limit].values('id', 'url', 'watched')) return JsonResponse({ 'results': results, diff --git a/static/links/main.js b/static/links/main.js index 7e12002..1b699e8 100644 --- a/static/links/main.js +++ b/static/links/main.js @@ -4,7 +4,6 @@ const newLinksContainer = document.getElementById('newLinksContainer'); const watchedLinksContainer = document.getElementById('watchedLinksContainer'); const PER_PAGE = 8; -const WATCHED = false; let currentPage = 1; let linksData = []; @@ -15,7 +14,7 @@ function extractReelId(url) { } function loadLinks() { - const cacheKeyWatched = `links_cache_page_${currentPage}_per_${PER_PAGE}&watched='true'`; + const cacheKeyWatched = `links_cache_page_${currentPage}_per_${PER_PAGE}&watched='True'`; const cachedWatched = localStorage.getItem(cacheKeyWatched); const cacheKey = `links_cache_page_${currentPage}_per_${PER_PAGE}`; @@ -38,7 +37,7 @@ function loadLinks() { } // Always fetch fresh data in the background - fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}&watched='true'`) + fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}&watched='True'`) .then(response => response.json()) .then(data => { localStorage.setItem(cacheKeyWatched, JSON.stringify(data));