diff options
| author | 2021-07-24 20:33:11 -0400 | |
|---|---|---|
| committer | 2021-07-24 20:33:11 -0400 | |
| commit | 0d55308776a029517899f8f26d454b0bb920a9ee (patch) | |
| tree | 3320f2f23f820ac68b8d4b4d2274bdc1668f1a43 /pydis_site/apps/resources/views | |
| parent | Remove extra newline from end of file (there is now one newline). (diff) | |
Added type annotations; refactored.
Diffstat (limited to 'pydis_site/apps/resources/views')
| -rw-r--r-- | pydis_site/apps/resources/views/resources.py | 28 | 
1 files changed, 15 insertions, 13 deletions
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py index f88a23fb..2414e48b 100644 --- a/pydis_site/apps/resources/views/resources.py +++ b/pydis_site/apps/resources/views/resources.py @@ -1,3 +1,4 @@ +from django.http import HttpRequest, HttpResponse  from django.shortcuts import render  from pydis_site.apps.resources.utils import get_resources_meta @@ -5,20 +6,21 @@ from pydis_site.apps.resources.utils import get_resources_meta  RESOURCE_META_TAGS = get_resources_meta() -def format_checkbox_options(options: str) -> list: +def format_checkbox_options(options: str) -> list[str]:      """Split up the comma separated parameters into a list.""" -    if options: -        return options.split(",")[:-1] -    return list() +    return options.split(",")[:-1] if options else [] -def resource_view(request): +def resource_view(request: HttpRequest) -> HttpResponse:      """View for resources index page.""" -    context = { -        "checkboxOptions": format_checkbox_options(request.GET.get("checkboxOptions")), -        "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") -    } -    return render(request, template_name="resources/resources.html", context=context) +    return render( +        request, +        template_name="resources/resources.html", +        context={ +            "checkboxOptions": format_checkbox_options(request.GET.get("checkboxOptions")), +            "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") +        } +    )  |