feat(home/models.py): add CoursePage page with group restriction

This commit is contained in:
2026-03-11 12:24:47 +01:00
parent 80c10193af
commit 8fea64e3fb

View File

@@ -2,9 +2,39 @@ from django.db import models
from wagtail.models import Page
from wagtail.fields import RichTextField
from django.contrib.auth.models import Group
class HomePage(Page):
body = RichTextField(blank=True)
content_panels = Page.content_panels + ["body"]
class CoursePage(Page):
body = RichTextField(blank=True)
group = models.ForeignKey(
Group,
on_delete=models.CASCADE,
null=True,
blank=True,
help_text="Only members of this group can access this course.",
)
content_panels = Page.content_panels + [
"body",
"group",
]
def serve(self, request):
if self.group:
if (
not request.user.is_authenticated
or self.group not in request.user.groups.all()
):
from django.shortcuts import render
# render 403.html
return render(request, "403.html", status=403)
return super().serve(request)