From a31f676b46a4d904954b8b7227dcde779aedca54 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Mon, 5 Dec 2022 19:21:00 -0700 Subject: Policy pages and signup tests. Fixes #113 --- core/views.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'core/views.py') diff --git a/core/views.py b/core/views.py index ea8a1ca..a09d925 100644 --- a/core/views.py +++ b/core/views.py @@ -1,10 +1,13 @@ +import markdown_it from django.http import JsonResponse from django.templatetags.static import static from django.utils.decorators import method_decorator +from django.utils.safestring import mark_safe from django.views.generic import TemplateView, View from activities.views.timelines import Home from core.decorators import cache_page +from core.models import Config from users.models import Identity @@ -22,6 +25,9 @@ class LoggedOutHomepage(TemplateView): def get_context_data(self): return { + "about": mark_safe( + markdown_it.MarkdownIt().render(Config.system.site_about) + ), "identities": Identity.objects.filter( local=True, discoverable=True, @@ -60,3 +66,26 @@ class AppManifest(View): ], } ) + + +class FlatPage(TemplateView): + """ + Serves a "flat page" from a config option, + returning 404 if it is empty. + """ + + template_name = "flatpage.html" + config_option = None + title = None + + def get_context_data(self): + if self.config_option is None: + raise ValueError("No config option provided") + # Get raw content + content = getattr(Config.system, self.config_option) + # Render it + html = markdown_it.MarkdownIt().render(content) + return { + "title": self.title, + "content": mark_safe(html), + } -- cgit v1.2.3