pagination behaves well with empty results
This commit is contained in:
parent
247fe8e206
commit
f6dfb7b0b7
|
@ -110,7 +110,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-5">
|
<div class="row mb-5">
|
||||||
<div class="container-fluid p-0 w-100 h-100">
|
<div class="container-fluid p-0 w-100 h-100">
|
||||||
{% if is_empty %}
|
{% if not posts %}
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<img src="/media/img/http/404.svg"
|
<img src="/media/img/http/404.svg"
|
||||||
class="img-fluid pb-5 pt-2 darkmode-invert"
|
class="img-fluid pb-5 pt-2 darkmode-invert"
|
||||||
|
@ -172,6 +172,7 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% empty %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<nav aria-label="Page navigation example" class="mt-5">
|
<nav aria-label="Page navigation example" class="mt-5">
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import ast
|
import ast
|
||||||
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.http.response import Http404, HttpResponse
|
from django.http.response import Http404, HttpResponse
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
|
@ -45,7 +46,6 @@ class Post(DetailView):
|
||||||
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class Browse(ListView):
|
class Browse(ListView):
|
||||||
"""
|
"""
|
||||||
Scroll through a list of blog posts
|
Scroll through a list of blog posts
|
||||||
|
@ -57,8 +57,9 @@ class Browse(ListView):
|
||||||
model = BlogPost
|
model = BlogPost
|
||||||
template_name = "blog/browse.html"
|
template_name = "blog/browse.html"
|
||||||
context_object_name = "posts"
|
context_object_name = "posts"
|
||||||
paginate_by = 20
|
paginate_by = 2
|
||||||
allow_empty = False # but we have a special get method
|
allow_empty = False # but we have a special get method
|
||||||
|
allow_empty = True
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
objects = BlogPost.objects.all()
|
objects = BlogPost.objects.all()
|
||||||
|
@ -97,7 +98,6 @@ class Browse(ListView):
|
||||||
keywords.append(Keyword.objects.get(slug=raw_keyword))
|
keywords.append(Keyword.objects.get(slug=raw_keyword))
|
||||||
except Keyword.DoesNotExist:
|
except Keyword.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
logger.debug(f"found kws: {keywords}")
|
|
||||||
objects = objects.filter(keywords__in=keywords)
|
objects = objects.filter(keywords__in=keywords)
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,5 @@ document.querySelectorAll(".reset-empty-button").forEach((element) => {
|
||||||
// smaller cards depending on viewport
|
// smaller cards depending on viewport
|
||||||
document.querySelectorAll(".cardrow").forEach((element) => {
|
document.querySelectorAll(".cardrow").forEach((element) => {
|
||||||
var level = Math.min(Math.floor(screen.width / 200), 6);
|
var level = Math.min(Math.floor(screen.width / 200), 6);
|
||||||
console.log(level);
|
|
||||||
element.classList.add("row-cols-" + level);
|
element.classList.add("row-cols-" + level);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue