diff options
author | Matthew Lemon <y@yulqen.org> | 2024-09-01 21:13:57 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-09-01 21:14:42 +0100 |
commit | e727913b9d8e28fccede007aaf5558a5bfa8900c (patch) | |
tree | 3c9293881c6c2212cf143ab5b852d5147b02d800 /pyblackbird_cc/resources/views.py | |
parent | 1d0522ea2d9197b1c4e9a051b829a8bfadf40115 (diff) |
wip: implementing the tabbed filter for standard resources
- it is filtering Featured resources too and it shouldn't. Fix.
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-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) |