41 lines
995 B
Python
41 lines
995 B
Python
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)
|