From 6933d51c0f8aec48869eaaa00a004c926f8c093c Mon Sep 17 00:00:00 2001 From: Brock Whittaker Date: Mon, 24 Jul 2017 17:35:22 -0700 Subject: [PATCH] views/integrations: Change non-generic HelpView to MarkdownDirectoryView. The HelpView class will render a directory as markdown with an index HTML page. This however can also be used for other generics and applied to the API pages as well, so change the class to a generic class and specify the path templates and names. Tweaked by tabbott and Eeshan Garg. --- zerver/views/integrations.py | 9 ++++----- zproject/urls.py | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/zerver/views/integrations.py b/zerver/views/integrations.py index 0ae4854670..c27402efff 100644 --- a/zerver/views/integrations.py +++ b/zerver/views/integrations.py @@ -50,9 +50,8 @@ class APIView(ApiURLView): template_name = 'zerver/api.html' -class HelpView(ApiURLView): - template_name = 'zerver/help/main.html' - path_template = 'zerver/help/%s.md' +class MarkdownDirectoryView(ApiURLView): + path_template = "" def get_path(self, article): # type: (str) -> str @@ -65,7 +64,7 @@ class HelpView(ApiURLView): def get_context_data(self, **kwargs): # type: (**Any) -> Dict[str, Any] article = kwargs["article"] - context = super(HelpView, self).get_context_data() # type: Dict[str, Any] + context = super().get_context_data() # type: Dict[str, Any] path = self.get_path(article) try: loader.get_template(path) @@ -81,7 +80,7 @@ class HelpView(ApiURLView): def get(self, request, article=""): # type: (HttpRequest, str) -> HttpResponse path = self.get_path(article) - result = super(HelpView, self).get(self, article=article) + result = super().get(self, article=article) try: loader.get_template(path) except loader.TemplateDoesNotExist: diff --git a/zproject/urls.py b/zproject/urls.py index b73fc4682f..d17dad4378 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -8,7 +8,7 @@ import os import zerver.forms from zproject import dev_urls from zproject.legacy_urls import legacy_urls -from zerver.views.integrations import IntegrationView, APIView, HelpView +from zerver.views.integrations import IntegrationView, APIView, MarkdownDirectoryView from zerver.lib.integrations import WEBHOOK_INTEGRATIONS from zerver.webhooks import github_dispatcher @@ -543,7 +543,9 @@ urls += [ urls += [url(r'^', include('social_django.urls', namespace='social'))] # User documentation site -urls += [url(r'^help/(?P
.*)$', HelpView.as_view(template_name='zerver/help/main.html'))] +urls += [url(r'^help/(?P
.*)$', + MarkdownDirectoryView.as_view(template_name='zerver/help/main.html', + path_template='/zerver/help/%s.md'))] if settings.DEVELOPMENT: urls += dev_urls.urls