-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodels.py
More file actions
69 lines (57 loc) · 2.07 KB
/
models.py
File metadata and controls
69 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, InlinePanel, ObjectList, TabbedInterface
from wagtail.api import APIField
from cms.common.managers import CommonPageManager
from cms.dashboard.enums import (
DEFAULT_RELATED_LINKS_LAYOUT_FIELD_LENGTH,
RelatedLinksLayoutEnum,
)
from cms.dashboard.models import (
UKHSAPage,
UKHSAPageRelatedLink,
)
from cms.dynamic_content import help_texts
from cms.dynamic_content.announcements import Announcement
class CommonPage(UKHSAPage):
related_links_layout = models.CharField(
verbose_name="Layout",
help_text=help_texts.RELATED_LINKS_LAYOUT_FIELD,
default=RelatedLinksLayoutEnum.Footer.value,
max_length=DEFAULT_RELATED_LINKS_LAYOUT_FIELD_LENGTH,
choices=RelatedLinksLayoutEnum.choices(),
)
content_panels = UKHSAPage.content_panels + [
FieldPanel("body"),
]
sidebar_content_panels = [
FieldPanel("related_links_layout"),
InlinePanel("related_links", heading="Related links", label="Related link"),
]
# Sets which fields to expose on the API
api_fields = UKHSAPage.api_fields + [
APIField("related_links_layout"),
APIField("related_links"),
APIField("search_description"),
]
# Tabs to position at the top of the view
edit_handler = TabbedInterface(
[
ObjectList(content_panels, heading="Content"),
ObjectList(sidebar_content_panels, heading="Related Links"),
ObjectList(UKHSAPage.announcement_content_panels, heading="Announcements"),
ObjectList(UKHSAPage.promote_panels, heading="Promote"),
]
)
objects = CommonPageManager()
class CommonPageRelatedLink(UKHSAPageRelatedLink):
page = ParentalKey(
CommonPage, on_delete=models.SET_NULL, null=True, related_name="related_links"
)
class CommonPageAnnouncement(Announcement):
page = ParentalKey(
CommonPage,
on_delete=models.SET_NULL,
null=True,
related_name="announcements",
)