diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-26 15:56:17 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-26 15:56:17 +0100 |
commit | d209dcbbcc36e65b8e16aca94add3f39de6414ef (patch) | |
tree | 96c38b555688d97024fb771a172ce36112c106d9 /pyblackbird_cc/resources/views.py | |
parent | eeaa3c469b33e614941596a04d56af3be1290456 (diff) |
Basic feature slot presentation in index page
Diffstat (limited to 'pyblackbird_cc/resources/views.py')
-rw-r--r-- | pyblackbird_cc/resources/views.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pyblackbird_cc/resources/views.py b/pyblackbird_cc/resources/views.py index 9fcb77b..2bcb9c2 100644 --- a/pyblackbird_cc/resources/views.py +++ b/pyblackbird_cc/resources/views.py @@ -38,6 +38,7 @@ class ResourceInfo: snapshot_urls: dict[str, list[str]] thumbnail_filenames: list[str] thumbnail_urls: list[str] + feature_slot: int created: str updated: str @@ -98,6 +99,7 @@ def _extract_metadata_from_resource(resource_obj) -> ResourceInfo | None: snapshot_urls=snapshot_url_dict, thumbnail_filenames=resource_obj.thumbnail_filenames, thumbnail_urls=thumbnail_urls, + feature_slot=resource_obj.feature_slot, created=resource_obj.created_at, updated=resource_obj.updated_at, ) @@ -110,7 +112,11 @@ 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] - context = {"resource_list": resource_list} + # featured_resources = Resource.objects.filter(feature_slot__gt=0).all() + featured_resources = [r for r in resource_list if r.feature_slot] + breakpoint() + featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot) + context = {"resource_list": resource_list, "featured_resources": featured_resources} return render(request, "resources/resource_list.html", context) @@ -245,6 +251,7 @@ def create_resource(request): curriculum = form.cleaned_data["curriculum"] main_resource_category = form.cleaned_data["main_resource_category"] additional_resource_category = form.cleaned_data["additional_resource_category"] + feature_slot = form.cleaned_data["feature_slot"] try: resource = Resource.objects.create( @@ -255,6 +262,7 @@ def create_resource(request): curriculum=curriculum, main_resource_category=main_resource_category, additional_resource_category=additional_resource_category, + feature_slot=feature_slot, ) metadata_generator = create_metadata(pdf_files) |