From 5c37aee79c04d9199dc47b9d60f9899a0f6571d9 Mon Sep 17 00:00:00 2001 From: Leon Sandøy Date: Wed, 19 May 2021 09:02:21 +0200 Subject: 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. --- .../resources/communities/_category_info.yaml | 2 -- .../resources/courses/_category_info.yaml | 4 --- .../resources/interactive/_category_info.yaml | 4 --- .../resources/podcasts/_category_info.yaml | 4 --- .../resources/reading/_category_info.yaml | 2 -- .../resources/reading/books/_category_info.yaml | 5 --- .../reading/tutorials/_category_info.yaml | 5 --- .../resources/resources/tools/_category_info.yaml | 4 --- .../tools/accessibility/screen_readers.yaml | 7 ++++ .../resources/tools/accessibility/talon_voice.yaml | 6 ++++ .../tools/accessibility_tools/_category_info.yaml | 5 --- .../tools/accessibility_tools/screen_readers.yaml | 7 ---- .../tools/accessibility_tools/talon_voice.yaml | 6 ---- .../resources/tools/editors/_category_info.yaml | 5 --- .../resources/tools/ides/_category_info.yaml | 5 --- .../resources/resources/videos/_category_info.yaml | 2 -- pydis_site/apps/resources/tests/test_views.py | 13 +++----- .../testing_resources/testing/_category_info.yaml | 1 - .../testing/foobar/_category_info.yaml | 1 - pydis_site/apps/resources/urls.py | 2 +- pydis_site/apps/resources/utils.py | 37 ++++------------------ pydis_site/apps/resources/views/resources_list.py | 25 ++------------- 22 files changed, 27 insertions(+), 125 deletions(-) delete mode 100644 pydis_site/apps/resources/resources/communities/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/courses/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/interactive/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/podcasts/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/reading/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/reading/books/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/reading/tutorials/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/_category_info.yaml create mode 100644 pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml create mode 100644 pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/accessibility_tools/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/editors/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/tools/ides/_category_info.yaml delete mode 100644 pydis_site/apps/resources/resources/videos/_category_info.yaml delete mode 100644 pydis_site/apps/resources/tests/testing_resources/testing/_category_info.yaml delete mode 100644 pydis_site/apps/resources/tests/testing_resources/testing/foobar/_category_info.yaml 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 - our meta repo, and we'll consider adding it. -name: Tools diff --git a/pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml b/pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml new file mode 100644 index 00000000..39372956 --- /dev/null +++ b/pydis_site/apps/resources/resources/tools/accessibility/screen_readers.yaml @@ -0,0 +1,7 @@ +description: Screen readers are software programs that allow blind + or visually impaired users to read the text displayed on a computer screen with a speech synthesizer or braille display. + There are many different screen reader program options, + with this link describing many of them and their capabilities. +name: Screen Readers - American Foundation for the Blind +title_url: https://www.afb.org/blindness-and-low-vision/using-technology/assistive-technology-products/screen-readers +position: 1 diff --git a/pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml b/pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml new file mode 100644 index 00000000..9df5f66f --- /dev/null +++ b/pydis_site/apps/resources/resources/tools/accessibility/talon_voice.yaml @@ -0,0 +1,6 @@ +description: Talon is a tool being built that aims to bring programming, + realtime video gaming, command line, and full desktop computer proficiency to people + who have limited or no use of their hands. +name: Talon Voice +title_url: https://talonvoice.com/ +position: 0 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/accessibility_tools/screen_readers.yaml b/pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml deleted file mode 100644 index 39372956..00000000 --- a/pydis_site/apps/resources/resources/tools/accessibility_tools/screen_readers.yaml +++ /dev/null @@ -1,7 +0,0 @@ -description: Screen readers are software programs that allow blind - or visually impaired users to read the text displayed on a computer screen with a speech synthesizer or braille display. - There are many different screen reader program options, - with this link describing many of them and their capabilities. -name: Screen Readers - American Foundation for the Blind -title_url: https://www.afb.org/blindness-and-low-vision/using-technology/assistive-technology-products/screen-readers -position: 1 diff --git a/pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml b/pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml deleted file mode 100644 index 9df5f66f..00000000 --- a/pydis_site/apps/resources/resources/tools/accessibility_tools/talon_voice.yaml +++ /dev/null @@ -1,6 +0,0 @@ -description: Talon is a tool being built that aims to bring programming, - realtime video gaming, command line, and full desktop computer proficiency to people - who have limited or no use of their hands. -name: Talon Voice -title_url: https://talonvoice.com/ -position: 0 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("/", 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 -- cgit v1.2.3