aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2021-05-19 09:02:21 +0200
committerGravatar Leon Sandøy <[email protected]>2021-05-19 09:02:21 +0200
commit5c37aee79c04d9199dc47b9d60f9899a0f6571d9 (patch)
tree9041c01dc0124fe96be467de7bb994daa372efd3
parentAdd bulma-modal, we'll need it later. (diff)
Dramatically simplify resources.
We don't need _category_info, we don't need subcategories, we this will be much simpler now. Also, rglob is nice.
-rw-r--r--pydis_site/apps/resources/resources/communities/_category_info.yaml2
-rw-r--r--pydis_site/apps/resources/resources/courses/_category_info.yaml4
-rw-r--r--pydis_site/apps/resources/resources/interactive/_category_info.yaml4
-rw-r--r--pydis_site/apps/resources/resources/podcasts/_category_info.yaml4
-rw-r--r--pydis_site/apps/resources/resources/reading/_category_info.yaml2
-rw-r--r--pydis_site/apps/resources/resources/reading/books/_category_info.yaml5
-rw-r--r--pydis_site/apps/resources/resources/reading/tutorials/_category_info.yaml5
-rw-r--r--pydis_site/apps/resources/resources/tools/_category_info.yaml4
-rw-r--r--pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml (renamed from pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml)0
-rw-r--r--pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml (renamed from pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml)0
-rw-r--r--pydis_site/apps/resources/resources/tools/accessibility_tools/_category_info.yaml5
-rw-r--r--pydis_site/apps/resources/resources/tools/editors/_category_info.yaml5
-rw-r--r--pydis_site/apps/resources/resources/tools/ides/_category_info.yaml5
-rw-r--r--pydis_site/apps/resources/resources/videos/_category_info.yaml2
-rw-r--r--pydis_site/apps/resources/tests/test_views.py13
-rw-r--r--pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml1
-rw-r--r--pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml1
-rw-r--r--pydis_site/apps/resources/urls.py2
-rw-r--r--pydis_site/apps/resources/utils.py37
-rw-r--r--pydis_site/apps/resources/views/resources_list.py25
20 files changed, 14 insertions, 112 deletions
diff --git a/pydis_site/apps/resources/resources/communities/_category_info.yaml b/pydis_site/apps/resources/resources/communities/_category_info.yaml
deleted file mode 100644
index b9cb6533..00000000
--- a/pydis_site/apps/resources/resources/communities/_category_info.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-description: Partnered communities that share part of our mission.
-name: Communities
diff --git a/pydis_site/apps/resources/resources/courses/_category_info.yaml b/pydis_site/apps/resources/resources/courses/_category_info.yaml
deleted file mode 100644
index 948b48de..00000000
--- a/pydis_site/apps/resources/resources/courses/_category_info.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-description: Listing of best Python courses.
-name: Courses
-default_icon: regular/graduation-cap
-default_icon_color: black
diff --git a/pydis_site/apps/resources/resources/interactive/_category_info.yaml b/pydis_site/apps/resources/resources/interactive/_category_info.yaml
deleted file mode 100644
index 7e8f34d9..00000000
--- a/pydis_site/apps/resources/resources/interactive/_category_info.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-description: Learn Python with interactive courses, games, and programming challenges.
-name: Interactive
-default_icon: branding/python
-default_icon_color: black
diff --git a/pydis_site/apps/resources/resources/podcasts/_category_info.yaml b/pydis_site/apps/resources/resources/podcasts/_category_info.yaml
deleted file mode 100644
index 1d2d3ba5..00000000
--- a/pydis_site/apps/resources/resources/podcasts/_category_info.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-description: Notable podcasts about the Python ecosystem.
-name: Podcasts
-default_icon: regular/microphone-alt
-default_icon_color: black
diff --git a/pydis_site/apps/resources/resources/reading/_category_info.yaml b/pydis_site/apps/resources/resources/reading/_category_info.yaml
deleted file mode 100644
index 64b87e47..00000000
--- a/pydis_site/apps/resources/resources/reading/_category_info.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-description: Books and tutorials related to Python and popular third-party libraries and frameworks.
-name: Reading
diff --git a/pydis_site/apps/resources/resources/reading/books/_category_info.yaml b/pydis_site/apps/resources/resources/reading/books/_category_info.yaml
deleted file mode 100644
index ae092a20..00000000
--- a/pydis_site/apps/resources/resources/reading/books/_category_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-description: The best books for learning Python or Python Frameworks.
-name: Books
-default_icon: branding/python
-default_icon_color: black
-position: 0
diff --git a/pydis_site/apps/resources/resources/reading/tutorials/_category_info.yaml b/pydis_site/apps/resources/resources/reading/tutorials/_category_info.yaml
deleted file mode 100644
index a18b837d..00000000
--- a/pydis_site/apps/resources/resources/reading/tutorials/_category_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-description: Tutorials and references for those that are just getting started with Python.
-name: Tutorials
-default_icon: branding/python
-default_icon_color: black
-position: 1
diff --git a/pydis_site/apps/resources/resources/tools/_category_info.yaml b/pydis_site/apps/resources/resources/tools/_category_info.yaml
deleted file mode 100644
index 6b16baa6..00000000
--- a/pydis_site/apps/resources/resources/tools/_category_info.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-description: This page is a curated list of tools that we regularly recommend in the community.
- If you have a suggestion for something to add to this page, please create an issue in
- <a href="https://github.com/python-discord/meta/issues">our meta repo</a>, and we'll consider adding it.
-name: Tools
diff --git a/pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml b/pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml
index 39372956..39372956 100644
--- a/pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml
+++ b/pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml
diff --git a/pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml b/pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml
index 9df5f66f..9df5f66f 100644
--- a/pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml
+++ b/pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml
diff --git a/pydis_site/apps/resources/resources/tools/accessibility_tools/_category_info.yaml b/pydis_site/apps/resources/resources/tools/accessibility_tools/_category_info.yaml
deleted file mode 100644
index e770db07..00000000
--- a/pydis_site/apps/resources/resources/tools/accessibility_tools/_category_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-description: Accessibility tools that help people write Python code.
-name: Accessibility Tools
-default_icon: branding/python
-default_icon_color: black
-position: 2
diff --git a/pydis_site/apps/resources/resources/tools/editors/_category_info.yaml b/pydis_site/apps/resources/resources/tools/editors/_category_info.yaml
deleted file mode 100644
index 3cdfff3a..00000000
--- a/pydis_site/apps/resources/resources/tools/editors/_category_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-description: Lightweight code editors supporting Python
-name: Editors
-default_icon: branding/python
-default_icon_color: black
-position: 1
diff --git a/pydis_site/apps/resources/resources/tools/ides/_category_info.yaml b/pydis_site/apps/resources/resources/tools/ides/_category_info.yaml
deleted file mode 100644
index 614625a6..00000000
--- a/pydis_site/apps/resources/resources/tools/ides/_category_info.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-description: Fully-integrated development environments for serious Python work.
-name: IDEs
-default_icon: branding/python
-default_icon_color: black
-position: 0
diff --git a/pydis_site/apps/resources/resources/videos/_category_info.yaml b/pydis_site/apps/resources/resources/videos/_category_info.yaml
deleted file mode 100644
index 8192e021..00000000
--- a/pydis_site/apps/resources/resources/videos/_category_info.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-description: Excellent Youtube channels with content related to Python.
-name: Videos
diff --git a/pydis_site/apps/resources/tests/test_views.py b/pydis_site/apps/resources/tests/test_views.py
index 53685eef..568f4d13 100644
--- a/pydis_site/apps/resources/tests/test_views.py
+++ b/pydis_site/apps/resources/tests/test_views.py
@@ -19,16 +19,13 @@ class TestResourcesView(TestCase):
class TestResourcesListView(TestCase):
- @patch("pydis_site.apps.resources.views.resources_list.RESOURCES_PATH", TESTING_RESOURCES_PATH)
def test_valid_resource_list_200(self):
"""Check does site return code 200 when visiting valid resource list."""
- url = reverse("resources:resources", ("testing",))
+ url = reverse("resources:resources")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
- @patch("pydis_site.apps.resources.views.resources_list.RESOURCES_PATH", TESTING_RESOURCES_PATH)
- def test_invalid_resource_list_404(self):
- """Check does site return code 404 when trying to visit invalid resource list."""
- url = reverse("resources:resources", ("invalid",))
- response = self.client.get(url)
- self.assertEqual(response.status_code, 404)
+ @patch("pydis_site.apps.resources.utils.RESOURCES_PATH", TESTING_RESOURCES_PATH)
+ def test_filter_resource_list(self):
+ """TODO: Check that we can correctly filter resources with GET parameters."""
+ pass
diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml
deleted file mode 100644
index bae17ea3..00000000
--- a/pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml
+++ /dev/null
@@ -1 +0,0 @@
-name: Testing
diff --git a/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml b/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml
deleted file mode 100644
index eaac32d9..00000000
--- a/pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml
+++ /dev/null
@@ -1 +0,0 @@
-name: Foobar
diff --git a/pydis_site/apps/resources/urls.py b/pydis_site/apps/resources/urls.py
index 19142081..cd4f53e7 100644
--- a/pydis_site/apps/resources/urls.py
+++ b/pydis_site/apps/resources/urls.py
@@ -5,5 +5,5 @@ from pydis_site.apps.resources import views
app_name = "resources"
urlpatterns = [
path("", views.ResourcesView.as_view(), name="index"),
- path("<str:category>/", views.ResourcesListView.as_view(), name="resources")
+ path("list/", views.ResourcesListView.as_view(), name="resources")
]
diff --git a/pydis_site/apps/resources/utils.py b/pydis_site/apps/resources/utils.py
index 1855fc80..6e21e2ba 100644
--- a/pydis_site/apps/resources/utils.py
+++ b/pydis_site/apps/resources/utils.py
@@ -2,41 +2,16 @@ import typing as t
from pathlib import Path
import yaml
+from django.conf import settings
+RESOURCES_PATH = Path(settings.BASE_DIR, "pydis_site", "apps", "resources", "resources")
-def get_resources(path: Path) -> t.List[t.Dict]:
+
+def get_resources() -> t.List[t.Dict]:
"""Loads resource YAMLs from provided path."""
resources = []
- for item in path.iterdir():
- if item.is_file() and item.suffix == ".yaml" and item.name != "_category_info.yaml":
- resources.append(yaml.safe_load(item.read_text()))
+ for item in RESOURCES_PATH.rglob("*.yaml"):
+ resources.append(yaml.safe_load(item.read_text()))
return resources
-
-
-def get_subcategories(path: Path) -> t.List[t.Dict]:
- """Loads resources subcategories with their resources by provided path."""
- subcategories = []
-
- for item in path.iterdir():
- if item.is_dir() and item.joinpath("_category_info.yaml").exists():
- subcategories.append({
- "category_info": {
- **yaml.safe_load(
- item.joinpath("_category_info.yaml").read_text()
- ),
- "raw_name": item.name
- },
- "resources": [
- yaml.safe_load(subitem.read_text())
- for subitem in item.iterdir()
- if (
- subitem.is_file()
- and subitem.suffix == ".yaml"
- and subitem.name != "_category_info.yaml"
- )
- ]
- })
-
- return subcategories
diff --git a/pydis_site/apps/resources/views/resources_list.py b/pydis_site/apps/resources/views/resources_list.py
index 55f22993..0ec74d78 100644
--- a/pydis_site/apps/resources/views/resources_list.py
+++ b/pydis_site/apps/resources/views/resources_list.py
@@ -1,14 +1,8 @@
-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")
+from pydis_site.apps.resources.utils import get_resources
class ResourcesListView(TemplateView):
@@ -19,21 +13,6 @@ class ResourcesListView(TemplateView):
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
- }
+ context["resources"] = get_resources()
return context