2016-06-22 00:07:27 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-07-19 21:31:13 +00:00
|
|
|
from django.http import Http404
|
2016-06-22 00:07:27 +00:00
|
|
|
from django.db import models
|
2016-07-19 21:31:13 +00:00
|
|
|
from django.shortcuts import render
|
2016-06-22 00:07:27 +00:00
|
|
|
|
|
|
|
from modelcluster.fields import ParentalKey
|
|
|
|
|
|
|
|
from wagtail.wagtailcore import blocks
|
|
|
|
from wagtail.wagtailimages import blocks as imageblocks
|
|
|
|
from wagtail.wagtailcore.models import Page
|
|
|
|
from wagtail.wagtailcore.models import Orderable
|
|
|
|
from wagtail.wagtailcore.fields import RichTextField
|
|
|
|
from wagtail.wagtailcore.fields import StreamField
|
2016-07-19 21:31:13 +00:00
|
|
|
from wagtail.wagtailcore.url_routing import RouteResult
|
2016-06-22 00:07:27 +00:00
|
|
|
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
|
|
|
|
from wagtail.wagtailadmin.edit_handlers import InlinePanel
|
|
|
|
from wagtail.wagtailadmin.edit_handlers import FieldPanel
|
|
|
|
from wagtail.wagtailadmin.edit_handlers import PageChooserPanel
|
|
|
|
from wagtail.wagtailadmin.edit_handlers import StreamFieldPanel
|
|
|
|
from wagtail.wagtailsearch import index
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
ILLUSTRATION_ANTARCTICA = "antarctica.svg"
|
|
|
|
ILLUSTRATION_BRIDGE = "bridge.svg"
|
|
|
|
ILLUSTRATION_CASINO = "casino.svg"
|
|
|
|
ILLUSTRATION_CRADLE = "cradle.svg"
|
|
|
|
ILLUSTRATION_DEVIL = "devil.svg"
|
|
|
|
ILLUSTRATION_FALLS = "falls.svg"
|
|
|
|
ILLUSTRATION_HOBART = "hobart.svg"
|
|
|
|
ILLUSTRATION_LAVENDER = "lavender.svg"
|
|
|
|
ILLUSTRATION_TUZ = "tuz.svg"
|
|
|
|
ILLUSTRATION_WINEGLASS = "wineglass.svg"
|
|
|
|
|
|
|
|
ILLUSTRATION_TYPES = (
|
|
|
|
(ILLUSTRATION_ANTARCTICA, "Antarctica"),
|
|
|
|
(ILLUSTRATION_BRIDGE, "Bridge"),
|
|
|
|
(ILLUSTRATION_CASINO, "Casino"),
|
|
|
|
(ILLUSTRATION_CRADLE, "Cradle Mountain"),
|
|
|
|
(ILLUSTRATION_DEVIL, "Tasmanian Devil"),
|
|
|
|
(ILLUSTRATION_FALLS, "Waterfall"),
|
|
|
|
(ILLUSTRATION_HOBART, "Hobart"),
|
|
|
|
(ILLUSTRATION_LAVENDER, "Lavender"),
|
|
|
|
(ILLUSTRATION_TUZ, "Tuz"),
|
|
|
|
(ILLUSTRATION_WINEGLASS, "Wineglass"),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class BasicContentBlock(blocks.StructBlock):
|
2016-06-22 00:07:27 +00:00
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
class Meta:
|
|
|
|
template = "cms_pages/home_page_blocks/basic_content.html"
|
2016-06-22 00:07:27 +00:00
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
PANEL_BLUE_LEFT = "blue_left"
|
|
|
|
PANEL_WHITE_RIGHT = "white_right"
|
|
|
|
PANEL_TYPES = (
|
|
|
|
(PANEL_BLUE_LEFT, "Left-aligned image, blue-filtered image BG"),
|
|
|
|
(PANEL_WHITE_RIGHT, "Right-aligned image, white background"),
|
2016-06-26 01:49:14 +00:00
|
|
|
)
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
EXTERNAL_LINK_TWITTER = "twitter"
|
2016-06-30 07:25:50 +00:00
|
|
|
EXTERNAL_LINK_FACEBOOK = "facebook"
|
2016-06-26 22:01:42 +00:00
|
|
|
EXTERNAL_LINK_GENERIC = "generic"
|
2016-06-26 01:49:14 +00:00
|
|
|
|
|
|
|
EXTERNAL_LINK_TYPES = (
|
|
|
|
(EXTERNAL_LINK_TWITTER, "Twitter"),
|
2016-06-30 07:25:50 +00:00
|
|
|
(EXTERNAL_LINK_FACEBOOK, "Facebook"),
|
2016-06-26 01:49:14 +00:00
|
|
|
(EXTERNAL_LINK_GENERIC, "Generic URL"),
|
|
|
|
)
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
panel_type = blocks.ChoiceBlock(
|
|
|
|
choices=PANEL_TYPES,
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
heading = blocks.CharBlock(required=True)
|
|
|
|
inset_illustration = blocks.ChoiceBlock(
|
|
|
|
choices=ILLUSTRATION_TYPES,
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
background_image = imageblocks.ImageChooserBlock(
|
|
|
|
required=False,
|
|
|
|
help_text="This is used as the background image of a "
|
|
|
|
"blue-left block. It's not used for white-right."
|
|
|
|
)
|
|
|
|
body = blocks.RichTextBlock(required=True)
|
|
|
|
link = blocks.StructBlock([
|
|
|
|
("page", blocks.PageChooserBlock()),
|
|
|
|
("title", blocks.CharBlock(required=True)),
|
|
|
|
])
|
|
|
|
external_links = blocks.ListBlock(
|
|
|
|
blocks.StructBlock([
|
|
|
|
("alt", blocks.CharBlock(required=True)),
|
|
|
|
("icon", blocks.ChoiceBlock(
|
|
|
|
choices=EXTERNAL_LINK_TYPES,
|
2016-06-26 01:49:14 +00:00
|
|
|
required=True,
|
|
|
|
)),
|
2016-06-26 22:01:42 +00:00
|
|
|
("url", blocks.URLBlock(required=True)
|
|
|
|
)])
|
|
|
|
)
|
|
|
|
|
|
|
|
class HomePage(Page):
|
|
|
|
|
|
|
|
body = StreamField([
|
|
|
|
("basic_content", BasicContentBlock()),
|
2016-06-22 00:07:27 +00:00
|
|
|
# TODO: keynotes
|
|
|
|
# TODO: other bits
|
|
|
|
])
|
|
|
|
|
|
|
|
content_panels = Page.content_panels + [
|
|
|
|
StreamFieldPanel('body')
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Content pages
|
|
|
|
class AbstractContentPage(Page):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
intro = models.CharField(max_length=250)
|
|
|
|
body = RichTextField(blank=True)
|
2016-06-26 22:01:42 +00:00
|
|
|
background_image = models.ForeignKey(
|
2016-06-22 00:07:27 +00:00
|
|
|
'wagtailimages.Image',
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
related_name='+'
|
|
|
|
)
|
|
|
|
|
|
|
|
search_fields = Page.search_fields + [
|
|
|
|
index.SearchField('intro'),
|
|
|
|
index.SearchField('body'),
|
|
|
|
]
|
|
|
|
|
|
|
|
content_panels = Page.content_panels + [
|
2016-06-26 22:01:42 +00:00
|
|
|
ImageChooserPanel('background_image'),
|
2016-06-22 00:07:27 +00:00
|
|
|
FieldPanel('intro'),
|
|
|
|
FieldPanel('body', classname="full")
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ContentPage(AbstractContentPage):
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
inset_illustration = models.CharField(
|
|
|
|
choices=ILLUSTRATION_TYPES,
|
|
|
|
max_length=256,
|
2016-06-22 00:07:27 +00:00
|
|
|
)
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
content_panels = AbstractContentPage.content_panels + [
|
|
|
|
FieldPanel('inset_illustration')
|
|
|
|
]
|
2016-06-22 00:07:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
# News pages
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
class NewsIndexPage(AbstractContentPage):
|
|
|
|
|
2016-07-19 21:31:13 +00:00
|
|
|
def route(self, request, path_components):
|
|
|
|
|
|
|
|
# Try the default to allow children to resolve
|
|
|
|
try:
|
|
|
|
return super(NewsIndexPage, self).route(request, path_components)
|
|
|
|
except Http404:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if path_components:
|
|
|
|
# tell Wagtail to call self.serve() with an additional 'path_components' kwarg
|
|
|
|
return RouteResult(self, kwargs={'path_components': path_components})
|
|
|
|
else:
|
|
|
|
raise Http404
|
|
|
|
|
|
|
|
def serve(self, request, path_components=[]):
|
|
|
|
''' Optionally return the RSS version of the page '''
|
|
|
|
|
|
|
|
template = self.template
|
|
|
|
|
|
|
|
if path_components and path_components[0] == "rss":
|
|
|
|
template = template.replace(".html", ".rss")
|
|
|
|
|
|
|
|
r = super(NewsIndexPage, self).serve(request)
|
|
|
|
r.template_name = template
|
|
|
|
return r
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
def child_pages(self):
|
|
|
|
return NewsPage.objects.live().child_of(self).specific().order_by("-date")
|
2016-06-22 00:07:27 +00:00
|
|
|
|
|
|
|
subpage_types = [
|
|
|
|
"NewsPage",
|
|
|
|
]
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
content_panels = AbstractContentPage.content_panels
|
2016-06-22 00:07:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NewsPage(AbstractContentPage):
|
2016-06-26 22:01:42 +00:00
|
|
|
|
2016-06-22 00:07:27 +00:00
|
|
|
date = models.DateField("Post date")
|
|
|
|
|
2016-06-26 22:01:42 +00:00
|
|
|
portrait_image = models.ForeignKey(
|
|
|
|
'wagtailimages.Image',
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
related_name='+'
|
|
|
|
)
|
|
|
|
|
2016-06-22 00:07:27 +00:00
|
|
|
parent_page_types = [
|
|
|
|
NewsIndexPage,
|
|
|
|
]
|
|
|
|
|
|
|
|
content_panels = AbstractContentPage.content_panels + [
|
|
|
|
FieldPanel('date'),
|
2016-06-26 22:01:42 +00:00
|
|
|
ImageChooserPanel('portrait_image'),
|
2016-06-22 00:07:27 +00:00
|
|
|
]
|