aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/resources/views
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2021-05-16 18:42:50 +0100
committerGravatar GitHub <[email protected]>2021-05-16 18:42:50 +0100
commit8c7c3b137fb6c60818d29ac3d14ebb397357ee0e (patch)
treefec5581d5e27fc860db6424f7c1d6a3a71565693 /pydis_site/apps/resources/views
parentResolve conflicts (diff)
parentMerge pull request #501 from python-discord/update/sir-lancebot-env-vars (diff)
Merge branch 'main' into fix_327
Diffstat (limited to 'pydis_site/apps/resources/views')
-rw-r--r--pydis_site/apps/resources/views/__init__.py4
-rw-r--r--pydis_site/apps/resources/views/resources.py7
-rw-r--r--pydis_site/apps/resources/views/resources_list.py39
3 files changed, 50 insertions, 0 deletions
diff --git a/pydis_site/apps/resources/views/__init__.py b/pydis_site/apps/resources/views/__init__.py
new file mode 100644
index 00000000..8eb383b5
--- /dev/null
+++ b/pydis_site/apps/resources/views/__init__.py
@@ -0,0 +1,4 @@
+from .resources import ResourcesView
+from .resources_list import ResourcesListView
+
+__all__ = ["ResourcesView", "ResourcesListView"]
diff --git a/pydis_site/apps/resources/views/resources.py b/pydis_site/apps/resources/views/resources.py
new file mode 100644
index 00000000..25ce3e50
--- /dev/null
+++ b/pydis_site/apps/resources/views/resources.py
@@ -0,0 +1,7 @@
+from django.views.generic import TemplateView
+
+
+class ResourcesView(TemplateView):
+ """View for resources index page."""
+
+ template_name = "resources/resources.html"
diff --git a/pydis_site/apps/resources/views/resources_list.py b/pydis_site/apps/resources/views/resources_list.py
new file mode 100644
index 00000000..55f22993
--- /dev/null
+++ b/pydis_site/apps/resources/views/resources_list.py
@@ -0,0 +1,39 @@
+from pathlib import Path
+from typing import Any, Dict
+
+import yaml
+from django.conf import settings
+from django.http import Http404
+from django.views.generic import TemplateView
+
+from pydis_site.apps.resources.utils import get_resources, get_subcategories
+
+RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "resources")
+
+
+class ResourcesListView(TemplateView):
+ """Shows specific resources list."""
+
+ template_name = "resources/resources_list.html"
+
+ def get_context_data(self, **kwargs) -> Dict[str, Any]:
+ """Add resources and subcategories data into context."""
+ context = super().get_context_data(**kwargs)
+
+ resource_path = RESOURCES_PATH / self.kwargs["category"]
+ if (
+ not resource_path.is_dir()
+ or not resource_path.joinpath("_category_info.yaml").exists()
+ ):
+ raise Http404
+
+ context["resources"] = get_resources(resource_path)
+ context["subcategories"] = get_subcategories(resource_path)
+ context["category_info"] = {
+ **yaml.safe_load(
+ resource_path.joinpath("_category_info.yaml").read_text()
+ ),
+ "raw_name": resource_path.name
+ }
+
+ return context