diff options
Diffstat (limited to '')
-rw-r--r-- | pyblackbird_cc/resources/views.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py index 04c8b2b..4df7208 100644 --- a/pyblackbird_cc/resources/views.py +++ b/pyblackbird_cc/resources/views.py @@ -17,7 +17,7 @@ from django.shortcuts import render from . import services from .forms import ResourceCreateForm, ResourceUpdateThumbnailsForm, ResourceUpdatePDFsForm from .forms import ResourceUpdateMetadataForm -from .models import PDFPageSnapshot, ResourceSubcategory +from .models import PDFPageSnapshot, ResourceSubcategory, ResourceCategory from .models import PDFResource from .models import Resource from .s3 import get_presigned_obj_url, upload_files_to_s3, upload_to_s3, upload_snapshotted_pages_to_s3 @@ -118,13 +118,27 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None: @login_required def index(request): resource_objs = Resource.objects.all() + categories = ResourceCategory.objects.all() + category = request.GET.get('category', 'all') + + if category != 'all': + resource_objs = resource_objs.filter(main_resource_category__name=category) + 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) + + # Create a separate queryset for Featured resources featured_resources = [r for r in resource_list if r.feature_slot] featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot) - context = {"page_obj": page_obj, "resource_list": resource_list, "featured_resources": featured_resources} + + context = { + "page_obj": page_obj, + "categories": categories, + "featured_resources": featured_resources, + "selected_category": category, + } return render(request, "resources/resource_list.html", context) |