From 2f0db972deb5ed8168ce19bc44bb2778b46d114f Mon Sep 17 00:00:00 2001 From: Johannes Erwerle Date: Sun, 19 Apr 2026 09:09:15 +0200 Subject: [PATCH] moved custom Markdown pages to configurable directory. --- README.md | 14 ++++++++++++++ .../community_backup/example_configuration.py | 2 ++ community_backup/community_backup/settings.py | 2 ++ community_backup/webui/views.py | 6 +++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6bf868d..f5b384d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,16 @@ Create a superuser account ``` +## Custom pages + +Some pages are specific to your installation. E.g. an imprint. + +Those files are markdown files that are rendered as HTML. You have to supply them and put them into the `MARKDOWN_PAGE_DIR`. + +The following files are expected: + +* `imprint.md` with your imprint information. + ## Settings ### BACKUP_USER @@ -120,3 +130,7 @@ The secret key used by django for session cookies and other things. ### DEBUG Django debug setting. + +### MARKDOWN_PAGE_DIR + +`MARKDOWN_PAGE_DIR` is the directory where customized markdown files are put. This directory is required. diff --git a/community_backup/community_backup/example_configuration.py b/community_backup/community_backup/example_configuration.py index cf06f1c..1ddb2ac 100644 --- a/community_backup/community_backup/example_configuration.py +++ b/community_backup/community_backup/example_configuration.py @@ -19,3 +19,5 @@ SECRET_KEY = "change me!" # SECURITY WARNING: don't run with debug turned on in production! # DEBUG = True + +MARKDOWN_PAGE_DIR = Path("./custom_md/") diff --git a/community_backup/community_backup/settings.py b/community_backup/community_backup/settings.py index 2e420e3..40d17a7 100644 --- a/community_backup/community_backup/settings.py +++ b/community_backup/community_backup/settings.py @@ -130,6 +130,7 @@ try: assert module.BACKUP_AUTHORIZED_KEYS, ( "The BACKUP_AUTHORIZED_KEYS setting is required." ) + assert module.MARKDOWN_PAGE_DIR, "The MARKDOWN_PAGE_DIR setting is required." except ModuleNotFoundError: print(f"could not find configuration file {config_module}") @@ -142,5 +143,6 @@ BACKUP_BORG_DIR = module.BACKUP_BORG_DIR BACKUP_AUTHORIZED_KEYS = module.BACKUP_AUTHORIZED_KEYS DATABASES = module.DATABASES SECRET_KEY = module.SECRET_KEY +MARKDOWN_PAGE_DIR = module.MARKDOWN_PAGE_DIR DEBUG = getattr(module, "DEBUG", False) diff --git a/community_backup/webui/views.py b/community_backup/webui/views.py index f265477..249f861 100644 --- a/community_backup/webui/views.py +++ b/community_backup/webui/views.py @@ -2,13 +2,12 @@ from django.shortcuts import get_object_or_404 from django.views.generic.base import TemplateView from django.views.generic import ListView, FormView from django.views.generic.edit import CreateView, UpdateView, DeleteView +from django.conf import settings from django.contrib.auth.models import User from django.contrib.auth.forms import BaseUserCreationForm from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin -from django.template.loader import get_template - from django.core.exceptions import ValidationError import markdown2 @@ -36,7 +35,8 @@ class MarkdownView(TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - source = get_template(self.md).template.source + + source = (settings.MARKDOWN_PAGE_DIR / self.md).read_text() context["markdown_content"] = markdown2.markdown(source) return context