summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/middleware.py16
-rw-r--r--core/models/config.py4
-rw-r--r--core/views.py29
3 files changed, 42 insertions, 7 deletions
diff --git a/core/middleware.py b/core/middleware.py
index bd89d1c..274f672 100644
--- a/core/middleware.py
+++ b/core/middleware.py
@@ -11,19 +11,21 @@ class ConfigLoadingMiddleware:
Caches the system config every request
"""
- refresh_interval: float = 30.0
+ refresh_interval: float = 5.0
def __init__(self, get_response):
self.get_response = get_response
self.config_ts: float = 0.0
def __call__(self, request):
- if (
- not getattr(Config, "system", None)
- or (time() - self.config_ts) >= self.refresh_interval
- ):
- Config.system = Config.load_system()
- self.config_ts = time()
+ # Allow test fixtures to force and lock the config
+ if not getattr(Config, "__forced__", False):
+ if (
+ not getattr(Config, "system", None)
+ or (time() - self.config_ts) >= self.refresh_interval
+ ):
+ Config.system = Config.load_system()
+ self.config_ts = time()
response = self.get_response(request)
return response
diff --git a/core/models/config.py b/core/models/config.py
index b18471e..53c729f 100644
--- a/core/models/config.py
+++ b/core/models/config.py
@@ -204,6 +204,10 @@ class Config(models.Model):
site_icon: UploadedImage = static("img/icon-128.png")
site_banner: UploadedImage = static("img/fjords-banner-600.jpg")
+ policy_terms: str = ""
+ policy_privacy: str = ""
+ policy_rules: str = ""
+
signup_allowed: bool = True
signup_invite_only: bool = False
signup_text: str = ""
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),
+ }