From bb401838ef8fa135a51d6a735dbbc3cc812d5e6c Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Sun, 30 Jan 2022 12:42:06 +0100 Subject: Ensure "Other" is always the bottom topic. --- pydis_site/apps/resources/views/resources.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py index 709fad6c..a5c2cf7c 100644 --- a/pydis_site/apps/resources/views/resources.py +++ b/pydis_site/apps/resources/views/resources.py @@ -1,5 +1,5 @@ -from pathlib import Path import typing as t +from pathlib import Path import yaml from django.core.handlers.wsgi import WSGIRequest @@ -79,15 +79,21 @@ class ResourceView(View): } } + # The bottom topic should always be "Other". + self.filters["Topics"]["filters"].remove("Other") + self.filters["Topics"]["filters"].append("Other") + def get(self, request: WSGIRequest, resource_type: t.Optional[str] = None) -> HttpResponse: """List out all the resources, and any filtering options from the URL.""" - # Add type filtering if the request is made to somewhere like /resources/video. # We also convert all spaces to dashes, so they'll correspond with the filters. - dashless_resource_type = resource_type.replace("-", " ") - if resource_type and dashless_resource_type.title() not in self.filters['Type']['filters']: - return HttpResponseNotFound() - resource_type = resource_type.replace(" ", "-") + if resource_type: + dashless_resource_type = resource_type.replace("-", " ") + + if dashless_resource_type.title() not in self.filters['Type']['filters']: + return HttpResponseNotFound() + + resource_type = resource_type.replace(" ", "-") return render( request, -- cgit v1.2.3