From e727913b9d8e28fccede007aaf5558a5bfa8900c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 1 Sep 2024 21:13:57 +0100 Subject: wip: implementing the tabbed filter for standard resources - it is filtering Featured resources too and it shouldn't. Fix. --- pyblackbird_cc/resources/views.py | 18 ++++++++- .../resources/resource_card_standard.html | 9 +++-- .../templates/resources/resource_list.html | 47 +++++++++++++++------- 3 files changed, 53 insertions(+), 21 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) diff --git a/pyblackbird_cc/templates/resources/resource_card_standard.html b/pyblackbird_cc/templates/resources/resource_card_standard.html index bdc3325..68ea0dc 100644 --- a/pyblackbird_cc/templates/resources/resource_card_standard.html +++ b/pyblackbird_cc/templates/resources/resource_card_standard.html @@ -2,9 +2,10 @@ {% load markdown_extras %} -
-
+
{{ resource.name }}
+ href="{% url 'resources:resource_detail' resource_id=resource.id %}">{{ resource.name }} +
{{ resource.age_range }} @@ -44,6 +46,5 @@
{% endif %}
-
\ No newline at end of file diff --git a/pyblackbird_cc/templates/resources/resource_list.html b/pyblackbird_cc/templates/resources/resource_list.html index 2ef0d48..5611bca 100644 --- a/pyblackbird_cc/templates/resources/resource_list.html +++ b/pyblackbird_cc/templates/resources/resource_list.html @@ -2,7 +2,7 @@ {% load static %} {% load markdown_extras %} {% block title %} - Joanna Lemon Learning - Resource List + Alphabet Learning - Resource List {% endblock title %} {% block content %} @@ -11,6 +11,7 @@
{# featured resources #} +{# TODO fix the tabbed navbar also fetching the selected Featured resources#} {% if featured_resources %}
Featured resources
@@ -19,11 +20,11 @@
{% for featured_resource in featured_resources %} {% if featured_resources|length == 1 %} -
+
{% elif featured_resources|length == 2 %} -
+
{% elif featured_resources|length == 3 %} -
+
{% endif %} {% include "resources/resource_card_featured.html" with resource=featured_resource %}
@@ -33,20 +34,36 @@

There are no featured resources

{% endif %} -{# standard resources #} -{% if page_obj.object_list %} + {# standard resources #}
Standard resources
-
+ + + + +
{% for resource in page_obj.object_list %} - {% include "resources/resource_card_standard.html" with resource=resource %} +
+ {% include "resources/resource_card_standard.html" with resource=resource %} +
{% endfor %}
+ {# Pagination #} {% if page_obj.has_other_pages %}
@@ -54,7 +71,8 @@
{% endif %} -{% else %} -

There are no resources

-{% endif %} -{% endblock content %} \ No newline at end of file +{% endblock content %} -- cgit v1.2.3