diff options
author | 2022-01-30 12:42:06 +0100 | |
---|---|---|
committer | 2022-01-30 12:42:06 +0100 | |
commit | bb401838ef8fa135a51d6a735dbbc3cc812d5e6c (patch) | |
tree | 0dbfc54eac7b260e1e8db726ace6841d2929edbd | |
parent | Add plural redirects, like /books. (diff) |
Ensure "Other" is always the bottom topic.
-rw-r--r-- | pydis_site/apps/resources/views/resources.py | 18 |
1 files 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, |