(release) Add Django changelog page
Expose the repository CHANGELOG.md through a staff-only Django view and link it from the main navigation. Render a small safe subset of Markdown without adding a runtime dependency, copy the changelog into the Docker image, and cover the page with view tests.
This commit is contained in:
@@ -15,6 +15,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from pobsync import __version__
|
||||
from pobsync.errors import PobsyncError
|
||||
from pobsync.config.defaults import DEFAULT_EXCLUDES, DEFAULT_RSYNC_ARGS
|
||||
|
||||
@@ -88,6 +89,28 @@ def dashboard(request):
|
||||
return render(request, "pobsync_backend/dashboard.html", context)
|
||||
|
||||
|
||||
@staff_member_required
|
||||
def changelog(request):
|
||||
changelog_path = Path(settings.BASE_DIR) / "CHANGELOG.md"
|
||||
try:
|
||||
changelog_text = changelog_path.read_text(encoding="utf-8")
|
||||
missing = False
|
||||
except FileNotFoundError:
|
||||
changelog_text = "CHANGELOG.md was not found in this installation."
|
||||
missing = True
|
||||
|
||||
return render(
|
||||
request,
|
||||
"pobsync_backend/changelog.html",
|
||||
{
|
||||
"app_version": __version__,
|
||||
"changelog_blocks": _parse_changelog(changelog_text),
|
||||
"changelog_path": changelog_path,
|
||||
"missing": missing,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@staff_member_required
|
||||
def self_check(request):
|
||||
checks = collect_self_checks()
|
||||
@@ -793,6 +816,49 @@ def _pretty_json(value: object) -> str:
|
||||
return json.dumps(value or {}, indent=2, sort_keys=True)
|
||||
|
||||
|
||||
def _parse_changelog(text: str) -> list[dict[str, object]]:
|
||||
blocks: list[dict[str, object]] = []
|
||||
paragraph: list[str] = []
|
||||
list_items: list[str] = []
|
||||
|
||||
def flush_paragraph() -> None:
|
||||
if paragraph:
|
||||
blocks.append({"kind": "paragraph", "text": " ".join(paragraph)})
|
||||
paragraph.clear()
|
||||
|
||||
def flush_list() -> None:
|
||||
if list_items:
|
||||
blocks.append({"kind": "list", "items": list(list_items)})
|
||||
list_items.clear()
|
||||
|
||||
for raw_line in text.splitlines():
|
||||
line = raw_line.strip()
|
||||
if not line:
|
||||
flush_paragraph()
|
||||
flush_list()
|
||||
continue
|
||||
|
||||
if line.startswith("#"):
|
||||
flush_paragraph()
|
||||
flush_list()
|
||||
marker, _space, heading = line.partition(" ")
|
||||
level = min(max(len(marker), 1), 3)
|
||||
blocks.append({"kind": "heading", "level": level, "text": heading.strip() or line.lstrip("#").strip()})
|
||||
continue
|
||||
|
||||
if line.startswith("- "):
|
||||
flush_paragraph()
|
||||
list_items.append(line[2:].strip())
|
||||
continue
|
||||
|
||||
flush_list()
|
||||
paragraph.append(line)
|
||||
|
||||
flush_paragraph()
|
||||
flush_list()
|
||||
return blocks
|
||||
|
||||
|
||||
def _snapshot_restore_guidance(snapshot: SnapshotRecord) -> dict[str, str]:
|
||||
source_path = Path(snapshot.path) / "data"
|
||||
destination_path = Path("/restore") / snapshot.host.host
|
||||
|
||||
Reference in New Issue
Block a user