aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/resources
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2022-01-31 18:02:59 +0100
committerGravatar Leon Sandøy <[email protected]>2022-01-31 18:02:59 +0100
commit91935d88476bade9701d354e82cafba912a33f69 (patch)
treebf9428423f5944e62bafd04a51b8a111a0a4e8ba /pydis_site/apps/resources
parentAdded margins and max-width to filtering column. (diff)
Get rid of invalid filters in the URL.
Diffstat (limited to 'pydis_site/apps/resources')
-rw-r--r--pydis_site/apps/resources/views/resources.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py
index a5c2cf7c..a38c3b59 100644
--- a/pydis_site/apps/resources/views/resources.py
+++ b/pydis_site/apps/resources/views/resources.py
@@ -1,3 +1,4 @@
+import json
import typing as t
from pathlib import Path
@@ -8,6 +9,7 @@ from django.shortcuts import render
from django.views import View
from pydis_site import settings
+from pydis_site.apps.resources.templatetags.as_css_class import as_css_class
RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "resources")
@@ -83,6 +85,14 @@ class ResourceView(View):
self.filters["Topics"]["filters"].remove("Other")
self.filters["Topics"]["filters"].append("Other")
+ # A complete list of valid filter names
+ self.valid_filters = {
+ "topics": [as_css_class(topic) for topic in self.filters["Topics"]["filters"]],
+ "payment_tiers": [as_css_class(tier) for tier in self.filters["Payment tiers"]["filters"]],
+ "type": [as_css_class(type_) for type_ in self.filters["Type"]["filters"]],
+ "difficulty": [as_css_class(tier) for tier in self.filters["Difficulty"]["filters"]],
+ }
+
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.
@@ -101,6 +111,7 @@ class ResourceView(View):
context={
"resources": self.resources,
"filters": self.filters,
+ "valid_filters": json.dumps(self.valid_filters),
"resource_type": resource_type,
}
)