2024-12-10 22:05:36 +00:00
|
|
|
"""
|
|
|
|
Base page and section models.
|
|
|
|
"""
|
|
|
|
|
2019-03-27 15:49:14 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.urls import reverse
|
2020-03-16 18:32:39 +00:00
|
|
|
from django.utils.text import slugify
|
2019-03-27 15:49:14 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from embed_video.fields import EmbedVideoField
|
2019-04-02 13:07:36 +00:00
|
|
|
|
2021-06-29 22:48:50 +00:00
|
|
|
from . import fields, mixins
|
2019-08-23 15:19:40 +00:00
|
|
|
|
2020-01-05 12:37:51 +00:00
|
|
|
|
2024-12-10 00:03:35 +00:00
|
|
|
class BasePage(mixins.Numbered, models.Model):
|
2024-12-10 22:05:36 +00:00
|
|
|
"""
|
|
|
|
Abstract base model for pages.
|
|
|
|
"""
|
2021-06-29 22:48:50 +00:00
|
|
|
|
|
|
|
title = fields.CharField(_("page"))
|
|
|
|
slug = fields.SlugField(_("slug"), blank=True, unique=True)
|
|
|
|
number = fields.PositiveIntegerField(_("number"), blank=True)
|
|
|
|
menu = fields.BooleanField(_("visible in menu"), default=True)
|
2019-03-27 15:49:14 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2019-08-26 07:47:52 +00:00
|
|
|
if not self.pk:
|
2021-06-29 22:48:50 +00:00
|
|
|
return str(_("New page"))
|
2020-01-02 18:32:15 +00:00
|
|
|
return self.title
|
2019-03-27 15:49:14 +00:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
if self.slug:
|
2021-06-29 22:48:50 +00:00
|
|
|
return reverse("cms:page", args=[self.slug])
|
|
|
|
return reverse("cms:page")
|
2019-03-27 15:49:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
2020-01-02 00:56:15 +00:00
|
|
|
abstract = True
|
2021-06-29 22:48:50 +00:00
|
|
|
verbose_name = _("page")
|
|
|
|
verbose_name_plural = _("pages")
|
|
|
|
ordering = ["number"]
|
|
|
|
|
|
|
|
|
2024-12-10 00:03:35 +00:00
|
|
|
class BaseSection(mixins.Numbered, models.Model):
|
2024-12-10 22:05:36 +00:00
|
|
|
"""
|
|
|
|
Abstract base model for sections.
|
|
|
|
"""
|
2019-03-27 15:49:14 +00:00
|
|
|
|
2020-03-21 17:49:41 +00:00
|
|
|
TYPES = []
|
2021-06-29 22:48:50 +00:00
|
|
|
title = fields.CharField(_("section"))
|
|
|
|
type = fields.CharField(_("type"))
|
|
|
|
number = fields.PositiveIntegerField(_("number"), blank=True)
|
|
|
|
content = fields.TextField(_("content"), blank=True)
|
|
|
|
image = fields.ImageField(_("image"), blank=True)
|
|
|
|
video = EmbedVideoField(
|
|
|
|
_("video"),
|
|
|
|
blank=True,
|
|
|
|
help_text=_("Paste a YouTube, Vimeo, or SoundCloud link"),
|
|
|
|
)
|
|
|
|
href = fields.CharField(_("link"), blank=True)
|
2024-12-10 22:08:03 +00:00
|
|
|
subject = fields.CharField(_("subject"), blank=True)
|
2019-03-27 15:49:14 +00:00
|
|
|
|
|
|
|
def number_with_respect_to(self):
|
|
|
|
return self.page.sections.all()
|
|
|
|
|
2020-03-16 18:32:39 +00:00
|
|
|
def get_absolute_url(self):
|
2021-06-29 22:48:50 +00:00
|
|
|
return self.page.get_absolute_url() + "#" + slugify(self.title)
|
2020-03-16 18:32:39 +00:00
|
|
|
|
2019-03-27 15:49:14 +00:00
|
|
|
def __str__(self):
|
2019-08-26 07:47:52 +00:00
|
|
|
if not self.pk:
|
2021-06-29 22:48:50 +00:00
|
|
|
return str(_("New section"))
|
2019-08-26 07:47:52 +00:00
|
|
|
elif not self.title:
|
2021-06-29 22:48:50 +00:00
|
|
|
return str(_("Untitled"))
|
2019-08-26 07:47:52 +00:00
|
|
|
else:
|
|
|
|
return self.title
|
2019-03-27 15:49:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
2019-12-31 12:05:12 +00:00
|
|
|
abstract = True
|
2021-06-29 22:48:50 +00:00
|
|
|
verbose_name = _("section")
|
|
|
|
verbose_name_plural = _("sections")
|
|
|
|
ordering = ["number"]
|