From 367ba267c4dbc6d406922f80bc4337ee9a0139a0 Mon Sep 17 00:00:00 2001 From: kosayoda Date: Tue, 23 Mar 2021 18:24:56 +0800 Subject: Rename `articles` to `pages`. Articles was a good name, but we want an `articles` category in the future. `/pages/guides/` and `/pages/articles/` are clearer in name than `/articles/guides/` and `/articles/articles/`. --- pydis_site/apps/content/views/__init__.py | 6 +- pydis_site/apps/content/views/article_category.py | 69 ----------------------- pydis_site/apps/content/views/articles.py | 16 ------ pydis_site/apps/content/views/page_category.py | 69 +++++++++++++++++++++++ pydis_site/apps/content/views/pages.py | 16 ++++++ 5 files changed, 88 insertions(+), 88 deletions(-) delete mode 100644 pydis_site/apps/content/views/article_category.py delete mode 100644 pydis_site/apps/content/views/articles.py create mode 100644 pydis_site/apps/content/views/page_category.py create mode 100644 pydis_site/apps/content/views/pages.py (limited to 'pydis_site/apps/content/views') diff --git a/pydis_site/apps/content/views/__init__.py b/pydis_site/apps/content/views/__init__.py index f92660d6..740d98e9 100644 --- a/pydis_site/apps/content/views/__init__.py +++ b/pydis_site/apps/content/views/__init__.py @@ -1,4 +1,4 @@ -from .article_category import ArticleOrCategoryView -from .articles import ArticlesView +from .page_category import PageOrCategoryView +from .pages import PagesView -__all__ = ["ArticleOrCategoryView", "ArticlesView"] +__all__ = ["PageOrCategoryView", "PagesView"] diff --git a/pydis_site/apps/content/views/article_category.py b/pydis_site/apps/content/views/article_category.py deleted file mode 100644 index 2a407b99..00000000 --- a/pydis_site/apps/content/views/article_category.py +++ /dev/null @@ -1,69 +0,0 @@ -import typing as t - -from django.conf import settings -from django.http import Http404 -from django.views.generic import TemplateView - -from pydis_site.apps.content import utils - - -class ArticleOrCategoryView(TemplateView): - """Handles article and category pages.""" - - def get_template_names(self) -> t.List[str]: - """Checks does this use article template or listing template.""" - location = self.kwargs["location"].split("/") - full_location = settings.ARTICLES_PATH.joinpath(*location) - - if full_location.is_dir(): - template_name = "content/listing.html" - elif full_location.with_suffix(".md").is_file(): - template_name = "content/article.html" - else: - raise Http404 - - return [template_name] - - def get_context_data(self, **kwargs) -> t.Dict[str, t.Any]: - """Assign proper context variables based on what resource user requests.""" - context = super().get_context_data(**kwargs) - - location: list = self.kwargs["location"].split("/") - full_location = settings.ARTICLES_PATH.joinpath(*location) - - if full_location.is_dir(): - context["category_info"] = utils.get_category(location) - context["content"] = utils.get_articles(location) - context["categories"] = utils.get_categories(location) - # Add trailing slash here to simplify template - context["path"] = "/".join(location) + "/" - context["in_category"] = True - elif full_location.with_suffix(".md").is_file(): - article_result = utils.get_article(location) - - if len(location) > 1: - context["category_data"] = utils.get_category(location[:-1]) - context["category_data"]["raw_name"] = location[:-1][-1] - else: - context["category_data"] = {"name": None, "raw_name": None} - - context["article"] = article_result - context["relevant_links"] = article_result["metadata"].get("relevant_links", {}) - else: - raise Http404 - - location.pop() - breadcrumb_items = [] - while len(location): - breadcrumb_items.insert( - 0, - { - "name": utils.get_category(location)["name"], - "path": "/".join(location) - } - ) - location.pop() - - context["breadcrumb_items"] = breadcrumb_items - - return context diff --git a/pydis_site/apps/content/views/articles.py b/pydis_site/apps/content/views/articles.py deleted file mode 100644 index 999002d0..00000000 --- a/pydis_site/apps/content/views/articles.py +++ /dev/null @@ -1,16 +0,0 @@ -from django.views.generic import TemplateView - -from pydis_site.apps.content.utils import get_articles, get_categories - - -class ArticlesView(TemplateView): - """Shows all content and categories.""" - - template_name = "content/listing.html" - - def get_context_data(self, **kwargs) -> dict: - """Add articles and categories data to template context.""" - context = super().get_context_data(**kwargs) - context["content"] = get_articles() - context["categories"] = get_categories() - return context diff --git a/pydis_site/apps/content/views/page_category.py b/pydis_site/apps/content/views/page_category.py new file mode 100644 index 00000000..f00a79ee --- /dev/null +++ b/pydis_site/apps/content/views/page_category.py @@ -0,0 +1,69 @@ +import typing as t + +from django.conf import settings +from django.http import Http404 +from django.views.generic import TemplateView + +from pydis_site.apps.content import utils + + +class PageOrCategoryView(TemplateView): + """Handles pages and page categories.""" + + def get_template_names(self) -> t.List[str]: + """Checks does this use page template or listing template.""" + location = self.kwargs["location"].split("/") + full_location = settings.PAGES_PATH.joinpath(*location) + + if full_location.is_dir(): + template_name = "content/listing.html" + elif full_location.with_suffix(".md").is_file(): + template_name = "content/page.html" + else: + raise Http404 + + return [template_name] + + def get_context_data(self, **kwargs) -> t.Dict[str, t.Any]: + """Assign proper context variables based on what resource user requests.""" + context = super().get_context_data(**kwargs) + + location: list = self.kwargs["location"].split("/") + full_location = settings.PAGES_PATH.joinpath(*location) + + if full_location.is_dir(): + context["category_info"] = utils.get_category(location) + context["content"] = utils.get_pages(location) + context["categories"] = utils.get_categories(location) + # Add trailing slash here to simplify template + context["path"] = "/".join(location) + "/" + context["in_category"] = True + elif full_location.with_suffix(".md").is_file(): + page_result = utils.get_page(location) + + if len(location) > 1: + context["category_data"] = utils.get_category(location[:-1]) + context["category_data"]["raw_name"] = location[:-1][-1] + else: + context["category_data"] = {"name": None, "raw_name": None} + + context["page"] = page_result + context["relevant_links"] = page_result["metadata"].get("relevant_links", {}) + else: + raise Http404 + + location.pop() + breadcrumb_items = [] + while len(location): + breadcrumb_items.insert( + 0, + { + "name": utils.get_category(location)["name"], + "path": "/".join(location) + } + ) + location.pop() + + context["breadcrumb_items"] = breadcrumb_items + + return context diff --git a/pydis_site/apps/content/views/pages.py b/pydis_site/apps/content/views/pages.py new file mode 100644 index 00000000..11ac0eeb --- /dev/null +++ b/pydis_site/apps/content/views/pages.py @@ -0,0 +1,16 @@ +from django.views.generic import TemplateView + +from pydis_site.apps.content.utils import get_pages, get_categories + + +class PagesView(TemplateView): + """Shows all pages and categories.""" + + template_name = "content/listing.html" + + def get_context_data(self, **kwargs) -> dict: + """Add page and category data to template context.""" + context = super().get_context_data(**kwargs) + context["content"] = get_pages() + context["categories"] = get_categories() + return context -- cgit v1.2.3