summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-17 15:30:51 -0700
committerAndrew Godwin2022-12-17 15:30:51 -0700
commit4d71da7ae1c961f9ecc59b449f5c5d6661931988 (patch)
treee5fb5820db21070760c58fabdd50d40db9a065a3
parentd08324e1590df4a7da19b70430e4abe364850d9b (diff)
downloadtakahe-4d71da7ae1c961f9ecc59b449f5c5d6661931988.tar.gz
takahe-4d71da7ae1c961f9ecc59b449f5c5d6661931988.tar.bz2
takahe-4d71da7ae1c961f9ecc59b449f5c5d6661931988.zip
Allow for remote policy pages
-rw-r--r--core/views.py19
-rw-r--r--users/views/admin/settings.py6
2 files changed, 17 insertions, 8 deletions
diff --git a/core/views.py b/core/views.py
index 71db5fd..462a041 100644
--- a/core/views.py
+++ b/core/views.py
@@ -1,5 +1,6 @@
import markdown_it
from django.http import JsonResponse
+from django.shortcuts import redirect
from django.templatetags.static import static
from django.utils.decorators import method_decorator
from django.utils.safestring import mark_safe
@@ -79,13 +80,21 @@ class FlatPage(TemplateView):
config_option = None
title = None
- def get_context_data(self):
+ def get(self, request, *args, **kwargs):
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)
+ self.content = getattr(Config.system, self.config_option)
+ # If the content is a plain URL, then redirect to it instead
+ if (
+ "\n" not in self.content
+ and " " not in self.content
+ and "://" in self.content
+ ):
+ return redirect(self.content)
+ return super().get(request, *args, **kwargs)
+
+ def get_context_data(self):
+ html = markdown_it.MarkdownIt().render(self.content)
return {
"title": self.title,
"content": mark_safe(html),
diff --git a/users/views/admin/settings.py b/users/views/admin/settings.py
index 4786d83..f72c0bd 100644
--- a/users/views/admin/settings.py
+++ b/users/views/admin/settings.py
@@ -174,17 +174,17 @@ class PoliciesSettings(AdminSettingsPage):
options = {
"policy_terms": {
"title": "Terms of Service Page",
- "help_text": "Will only be shown if it has content. Use Markdown for formatting.",
+ "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
"display": "textarea",
},
"policy_privacy": {
"title": "Privacy Policy Page",
- "help_text": "Will only be shown if it has content. Use Markdown for formatting.",
+ "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
"display": "textarea",
},
"policy_rules": {
"title": "Server Rules Page",
- "help_text": "Will only be shown if it has content. Use Markdown for formatting.",
+ "help_text": "Will only be shown if it has content. Use Markdown for formatting.\nIf you would like to redirect elsewhere, enter just a URL.",
"display": "textarea",
},
}