aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/views/article.py
diff options
context:
space:
mode:
Diffstat (limited to 'pydis_site/apps/content/views/article.py')
-rw-r--r--pydis_site/apps/content/views/article.py43
1 files changed, 19 insertions, 24 deletions
diff --git a/pydis_site/apps/content/views/article.py b/pydis_site/apps/content/views/article.py
index 42b92cee..90688c6f 100644
--- a/pydis_site/apps/content/views/article.py
+++ b/pydis_site/apps/content/views/article.py
@@ -4,21 +4,21 @@ from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
+from django.views.generic import TemplateView
from pydis_site.apps.content.utils import get_article, get_category, get_github_information
-class ArticleView(View):
+class ArticleView(TemplateView):
"""Shows specific guide page."""
- def get(
- self,
- request: WSGIRequest,
- article: str,
- category: Optional[str] = None
- ) -> HttpResponse:
- """Collect guide content and display it. When guide don't exist, return 404."""
- article_result = get_article(article, category)
+ template_name = "content/article.html"
+
+ def get_context_data(self, **kwargs):
+ """Add custom context info about article."""
+ context = super().get_context_data(**kwargs)
+ category = self.kwargs.get("category")
+ article_result = get_article(self.kwargs["article"], category)
if category is not None:
category_data = get_category(category)
@@ -26,18 +26,13 @@ class ArticleView(View):
else:
category_data = {"name": None, "raw_name": None}
- return render(
- request,
- "content/article.html",
- {
- "article": article_result,
- "category_data": category_data,
- "relevant_links": {
- link: value for link, value in zip(
- article_result["metadata"].get("relevant_links", "").split(","),
- article_result["metadata"].get("relevant_link_values", "").split(",")
- ) if link != "" and value != ""
- },
- "github_data": get_github_information(article, category),
- }
- )
+ context["article"] = article_result
+ context["category_data"] = category_data
+ context["relevant_links"] = {
+ link: value for link, value in zip(
+ article_result["metadata"].get("relevant_links", "").split(","),
+ article_result["metadata"].get("relevant_link_values", "").split(",")
+ ) if link != "" and value != ""
+ }
+ context["github_data"] = get_github_information(self.kwargs["article"], category)
+ return context