-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
65 lines (50 loc) · 2.11 KB
/
models.py
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
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField, StreamField
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.search import index
from social.models import Seo
from streams.blocks import CommonStreamBlock
class SectionIndexPage(Page, Seo):
alt_template = models.BooleanField(verbose_name="Use list style Index page instead?")
my_stream = StreamField(CommonStreamBlock(), null=True, blank=True)
def get_template(self, request):
if self.alt_template:
return 'sections/list_index_page.html'
return 'sections/section_index_page.html'
def get_context(self, request):
# Update context to include only published posts, ordered by reverse-chron
context = super().get_context(request)
if self.alt_template:
blogpages = self.get_children().live()
context['blogpages'] = blogpages
else :
blogpages = self.get_children().live().order_by('-first_published_at')
context['blogpages'] = blogpages
context['menuitems'] = request.site.root_page.get_descendants(
inclusive=True).live().in_menu()
return context
search_fields = Page.search_fields + [
index.SearchField('my_stream'),
]
content_panels = Page.content_panels + [
FieldPanel('alt_template'),
StreamFieldPanel('my_stream')
]
class SectionPage(Page, Seo):
body = RichTextField(blank=True)
my_stream = StreamField(CommonStreamBlock(), null=True, blank=True,)
parent_page_types = ['sections.SectionIndexPage']
def get_context(self, request):
context = super(SectionPage, self).get_context(request)
context['menuitems'] = request.site.root_page.get_descendants(
inclusive=True).live().in_menu()
return context
search_fields = Page.search_fields + [
index.SearchField('body'),
index.SearchField('my_stream'),
]
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
StreamFieldPanel('my_stream'),
]