|
@@ -10,13 +10,14 @@ from modelcluster.fields import ParentalKey
|
|
from taggit.models import Tag, TaggedItemBase
|
|
from taggit.models import Tag, TaggedItemBase
|
|
|
|
|
|
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
|
|
from wagtail.contrib.wagtailroutablepage.models import RoutablePageMixin, route
|
|
-from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel
|
|
|
|
|
|
+from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel, StreamFieldPanel
|
|
|
|
+from wagtail.wagtailcore.fields import StreamField
|
|
from wagtail.wagtailcore.models import Page, Orderable
|
|
from wagtail.wagtailcore.models import Page, Orderable
|
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
|
from wagtail.wagtailsearch import index
|
|
from wagtail.wagtailsearch import index
|
|
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
|
|
from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
|
|
|
|
|
|
-from bakerydemo.base.models import BasePageFieldsMixin
|
|
|
|
|
|
+from bakerydemo.base.blocks import BaseStreamBlock
|
|
|
|
|
|
|
|
|
|
class BlogPeopleRelationship(Orderable, models.Model):
|
|
class BlogPeopleRelationship(Orderable, models.Model):
|
|
@@ -47,7 +48,7 @@ class BlogPageTag(TaggedItemBase):
|
|
content_object = ParentalKey('BlogPage', related_name='tagged_items')
|
|
content_object = ParentalKey('BlogPage', related_name='tagged_items')
|
|
|
|
|
|
|
|
|
|
-class BlogPage(BasePageFieldsMixin, Page):
|
|
|
|
|
|
+class BlogPage(Page):
|
|
"""
|
|
"""
|
|
A Blog Page
|
|
A Blog Page
|
|
|
|
|
|
@@ -55,22 +56,37 @@ class BlogPage(BasePageFieldsMixin, Page):
|
|
ParentalKey's related_name in BlogPeopleRelationship. More docs:
|
|
ParentalKey's related_name in BlogPeopleRelationship. More docs:
|
|
http://docs.wagtail.io/en/v1.9/topics/pages.html#inline-models
|
|
http://docs.wagtail.io/en/v1.9/topics/pages.html#inline-models
|
|
"""
|
|
"""
|
|
|
|
+ introduction = models.TextField(
|
|
|
|
+ help_text='Text to describe the page',
|
|
|
|
+ blank=True)
|
|
|
|
+ image = models.ForeignKey(
|
|
|
|
+ 'wagtailimages.Image',
|
|
|
|
+ null=True,
|
|
|
|
+ blank=True,
|
|
|
|
+ on_delete=models.SET_NULL,
|
|
|
|
+ related_name='+',
|
|
|
|
+ help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
|
|
|
|
+ )
|
|
|
|
+ body = StreamField(
|
|
|
|
+ BaseStreamBlock(), verbose_name="Page body", blank=True
|
|
|
|
+ )
|
|
subtitle = models.CharField(blank=True, max_length=255)
|
|
subtitle = models.CharField(blank=True, max_length=255)
|
|
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
|
|
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)
|
|
date_published = models.DateField(
|
|
date_published = models.DateField(
|
|
"Date article published", blank=True, null=True
|
|
"Date article published", blank=True, null=True
|
|
)
|
|
)
|
|
|
|
|
|
- content_panels = BasePageFieldsMixin.content_panels + [
|
|
|
|
|
|
+ content_panels = Page.content_panels + [
|
|
|
|
+ FieldPanel('subtitle', classname="full"),
|
|
|
|
+ FieldPanel('introduction', classname="full"),
|
|
|
|
+ ImageChooserPanel('image'),
|
|
|
|
+ StreamFieldPanel('body'),
|
|
FieldPanel('date_published'),
|
|
FieldPanel('date_published'),
|
|
InlinePanel(
|
|
InlinePanel(
|
|
'blog_person_relationship', label="Author(s)",
|
|
'blog_person_relationship', label="Author(s)",
|
|
panels=None, min_num=1),
|
|
panels=None, min_num=1),
|
|
FieldPanel('tags'),
|
|
FieldPanel('tags'),
|
|
]
|
|
]
|
|
- # Inject subtitle panel after title field
|
|
|
|
- title_index = next((i for i, panel in enumerate(content_panels) if panel.field_name == 'title'), -1) # noqa
|
|
|
|
- content_panels.insert(title_index + 1, FieldPanel('subtitle'))
|
|
|
|
|
|
|
|
search_fields = Page.search_fields + [
|
|
search_fields = Page.search_fields + [
|
|
index.SearchField('title'),
|
|
index.SearchField('title'),
|
|
@@ -115,7 +131,7 @@ class BlogPage(BasePageFieldsMixin, Page):
|
|
subpage_types = []
|
|
subpage_types = []
|
|
|
|
|
|
|
|
|
|
-class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
|
|
|
|
|
|
+class BlogIndexPage(RoutablePageMixin, Page):
|
|
"""
|
|
"""
|
|
Index page for blogs.
|
|
Index page for blogs.
|
|
We need to alter the page model's context to return the child page objects,
|
|
We need to alter the page model's context to return the child page objects,
|
|
@@ -124,13 +140,24 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
|
|
RoutablePageMixin is used to allow for a custom sub-URL for the tag views
|
|
RoutablePageMixin is used to allow for a custom sub-URL for the tag views
|
|
defined above.
|
|
defined above.
|
|
"""
|
|
"""
|
|
|
|
+ introduction = models.TextField(
|
|
|
|
+ help_text='Text to describe the page',
|
|
|
|
+ blank=True)
|
|
|
|
+ image = models.ForeignKey(
|
|
|
|
+ 'wagtailimages.Image',
|
|
|
|
+ null=True,
|
|
|
|
+ blank=True,
|
|
|
|
+ on_delete=models.SET_NULL,
|
|
|
|
+ related_name='+',
|
|
|
|
+ help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
|
|
|
|
+ )
|
|
|
|
|
|
content_panels = Page.content_panels + [
|
|
content_panels = Page.content_panels + [
|
|
FieldPanel('introduction', classname="full"),
|
|
FieldPanel('introduction', classname="full"),
|
|
ImageChooserPanel('image'),
|
|
ImageChooserPanel('image'),
|
|
]
|
|
]
|
|
|
|
|
|
- # Defines what pages types can live under this page type
|
|
|
|
|
|
+ # Defines that only BlogPage objects can live under this index page
|
|
subpage_types = ['BlogPage']
|
|
subpage_types = ['BlogPage']
|
|
|
|
|
|
# Defines a function to access the children of the page (e.g. BlogPage
|
|
# Defines a function to access the children of the page (e.g. BlogPage
|
|
@@ -148,7 +175,6 @@ class BlogIndexPage(BasePageFieldsMixin, RoutablePageMixin, Page):
|
|
'-date_published')
|
|
'-date_published')
|
|
return context
|
|
return context
|
|
|
|
|
|
-
|
|
|
|
# This defines a Custom view that utilizes Tags. This view will return all
|
|
# This defines a Custom view that utilizes Tags. This view will return all
|
|
# related BlogPages for a given Tag or redirect back to the BlogIndexPage.
|
|
# related BlogPages for a given Tag or redirect back to the BlogIndexPage.
|
|
# More information on RoutablePages is at
|
|
# More information on RoutablePages is at
|