diff options
author | 2021-09-04 17:52:16 -0400 | |
---|---|---|
committer | 2021-09-04 17:52:16 -0400 | |
commit | 94fa4c6975653ef7ec104bda392a698348a7d66e (patch) | |
tree | 7a7edad3fc8beeff8a643d2f4ec930eb0034c36e /pydis_site/apps | |
parent | Drop -Option from {topic,type,etc}Option. (diff) |
Make an asterisk in the URL a wildcard.
This means that /resources/?topic=*&type=Book&payment=Paid&complexity=*` would return paid books of all topics and complexities.
Diffstat (limited to 'pydis_site/apps')
-rw-r--r-- | pydis_site/apps/resources/views/resources.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py index 60ec6d8f..a08f1d15 100644 --- a/pydis_site/apps/resources/views/resources.py +++ b/pydis_site/apps/resources/views/resources.py @@ -3,18 +3,22 @@ from django.shortcuts import render from pydis_site.apps.resources.resource_search import RESOURCE_TABLE, get_resources_from_search -RESOURCE_META_TAGS = {k: list(v) for k, v in RESOURCE_TABLE.items()} +RESOURCE_META_TAGS = {k: set(v) for k, v in RESOURCE_TABLE.items()} -def format_checkbox_options(options: str) -> list[str]: +def _parse_checkbox_options(options: str) -> set[str]: """Split up the comma separated query parameters for checkbox options into a list.""" - return options.split(",")[:-1] if options else [] + if not options: + return set() + if options == '*': + return {'*'} + return set(options.split(",")[:-1]) def resource_view(request: HttpRequest) -> HttpResponse: """View for resources index page.""" checkbox_options = { - a: set(format_checkbox_options(request.GET.get(b))) + a: _parse_checkbox_options(request.GET.get(b)) for a, b in ( ('topics', 'topic'), ('type', 'type'), @@ -23,6 +27,10 @@ def resource_view(request: HttpRequest) -> HttpResponse: ) } + # This allows for an asterisk in the URL to be a wildcard for that selection + checkbox_options = {k: (v if v != {'*'} else RESOURCE_META_TAGS[k]) + for k, v in checkbox_options.items()} + topics = sorted(RESOURCE_META_TAGS.get("topics")) return render( |