diff options
| author | 2021-07-25 19:49:01 -0500 | |
|---|---|---|
| committer | 2021-07-25 19:49:01 -0500 | |
| commit | 95e7b11df812e09baffe9ef16807e7d02a5e6f1d (patch) | |
| tree | 953105403b8b73c23ddbd179f7e87ae492d996d3 /pydis_site/apps/resources/views/resources.py | |
| parent | Updated type annotations; get_resources_meta now returns a dict of sorted lis... (diff) | |
working demo of smart resources search
I have incorporated a search that allows users to check boxes to filter resources. This is a working version, but the algo for searching likely needs to be modified. The frontend also needs some style updates. All necessary functionality should be present now though.
Diffstat (limited to 'pydis_site/apps/resources/views/resources.py')
| -rw-r--r-- | pydis_site/apps/resources/views/resources.py | 10 | 
1 files changed, 6 insertions, 4 deletions
| diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py index 2414e48b..ffb4f4a8 100644 --- a/pydis_site/apps/resources/views/resources.py +++ b/pydis_site/apps/resources/views/resources.py @@ -1,26 +1,28 @@  from django.http import HttpRequest, HttpResponse  from django.shortcuts import render -from pydis_site.apps.resources.utils import get_resources_meta +from pydis_site.apps.resources.utils import get_all_resources, get_resources_from_search, get_resources_meta  RESOURCE_META_TAGS = get_resources_meta()  def format_checkbox_options(options: str) -> list[str]: -    """Split up the comma separated parameters into a list.""" +    """Split up the comma separated query parameters for checkbox options into a list."""      return options.split(",")[:-1] if options else []  def resource_view(request: HttpRequest) -> HttpResponse:      """View for resources index page.""" +    checkbox_options = format_checkbox_options(request.GET.get("checkboxOptions"))      return render(          request,          template_name="resources/resources.html",          context={ -            "checkboxOptions": format_checkbox_options(request.GET.get("checkboxOptions")), +            "checkboxOptions": checkbox_options,              "topics": RESOURCE_META_TAGS.get("topics"),              "tag_types": RESOURCE_META_TAGS.get("type"),              "payment_tiers": RESOURCE_META_TAGS.get("payment_tiers"), -            "complexities": RESOURCE_META_TAGS.get("complexity") +            "complexities": RESOURCE_META_TAGS.get("complexity"), +            "resources": get_resources_from_search(checkbox_options)          }      ) | 
