aboutsummaryrefslogtreecommitdiffstats
path: root/pyblackbird_cc/resources/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-01 20:15:55 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-01 20:15:55 +0100
commit1d0522ea2d9197b1c4e9a051b829a8bfadf40115 (patch)
tree7890f97120558d7b7092f1228c2569509ae83e6e /pyblackbird_cc/resources/views.py
parent117e883061701f8cd8327b630a5a154b62a1df47 (diff)
Added pagination to the resource list page
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-rw-r--r--pyblackbird_cc/resources/views.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py
index eecb7cd..04c8b2b 100644
--- a/pyblackbird_cc/resources/views.py
+++ b/pyblackbird_cc/resources/views.py
@@ -7,6 +7,7 @@ from dataclasses import dataclass
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
+from django.core.paginator import Paginator
from django.db import IntegrityError
from django.db import transaction
from django.shortcuts import get_object_or_404
@@ -118,9 +119,12 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None:
def index(request):
resource_objs = Resource.objects.all()
resource_list = [_extract_metadata_from_resource(r) for r in resource_objs]
+ paginator = Paginator(resource_list, 20)
+ page_number = request.GET.get('page')
+ page_obj = paginator.get_page(page_number)
featured_resources = [r for r in resource_list if r.feature_slot]
featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot)
- context = {"resource_list": resource_list, "featured_resources": featured_resources}
+ context = {"page_obj": page_obj, "resource_list": resource_list, "featured_resources": featured_resources}
return render(request, "resources/resource_list.html", context)