Skip to content
Permalink
Browse files

Routable Pages

  • Loading branch information
KalobTaulien committed Feb 8, 2019
1 parent f184c8e commit d215c36a8aa5094d53e5b83e7b0cc4a3d05e04d5
@@ -1,15 +1,17 @@
"""Blog listing and blog detail pages."""
from django.db import models
from django.shortcuts import render

from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.core.fields import StreamField
from wagtail.core.models import Page
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.contrib.routable_page.models import RoutablePageMixin, route

from streams import blocks


class BlogListingPage(Page):
class BlogListingPage(RoutablePageMixin, Page):
"""Listing page lists all the Blog Detail Pages."""

template = "blog/blog_listing_page.html"
@@ -31,6 +33,12 @@ def get_context(self, request, *args, **kwargs):
context["posts"] = BlogDetailPage.objects.live().public()
return context

@route(r'^latest/?$', name="latest_posts")
def latest_blog_posts_only_shows_last_5(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)
context["posts"] = context["posts"][:1]
return render(request, "blog/latest_posts.html", context)


class BlogDetailPage(Page):
"""Blog detail page."""
@@ -1,4 +1,5 @@
from django.db import models
from django.shortcuts import render

from modelcluster.fields import ParentalKey

@@ -12,7 +13,7 @@
from wagtail.core.models import Page, Orderable
from wagtail.core.fields import RichTextField, StreamField
from wagtail.images.edit_handlers import ImageChooserPanel

from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from streams import blocks


@@ -31,7 +32,7 @@ class HomePageCarouselImages(Orderable):
panels = [ImageChooserPanel("carousel_image")]


class HomePage(Page):
class HomePage(RoutablePageMixin, Page):
"""Home page model."""

template = "home/home_page.html"
@@ -77,3 +78,8 @@ class Meta:

verbose_name = "Home Page"
verbose_name_plural = "Home Pages"

@route(r'^subscribe/$')
def the_subscribe_page(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)
return render(request, "home/subscribe.html", context)
@@ -36,6 +36,7 @@
'wagtail.contrib.modeladmin',
'wagtail.contrib.redirects',
'wagtail.contrib.settings',
'wagtail.contrib.routable_page',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
@@ -1,9 +1,11 @@
{% extends "base.html" %}

{% load wagtailimages_tags %}
{% load wagtailimages_tags wagtailroutablepage_tags %}

{% block content %}

<a href="{% routablepageurl page "latest_posts" %}">View Latest Posts Only</a>
<h2>special link is {{ a_special_link }}</h2>
<div class="container">
{% for post in posts %}
<div class="row mt-5 mb-5">
@@ -0,0 +1,27 @@
{% extends "base.html" %}

{% load wagtailimages_tags %}

{% block content %}

<div class="container">
<h1>Latest Posts</h1>
{% for post in posts %}
<div class="row mt-5 mb-5">
<div class="col-sm-3">
{% image post.blog_image fill-250x250 as blog_img %}
<a href="{{ post.url }}">
<img src="{{ blog_img.url }}" alt="{{ blog_img.alt }}">
</a>
</div>
<div class="col-sm-9">
<a href="{{ post.url }}">
<h2>{{ post.custom_title }}</h2>
{# @todo add a summary field to BlogDetailPage; make it a RichTextField with only Bold and Italic enabled. #}
<a href="{{ post.url }}" class="btn btn-primary mt-4">Read More</a>
</a>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
@@ -0,0 +1,7 @@
{% extends "base.html" %}

{% block content %}

@todo add a django form that lets people self subscribe to this website using Subscribers model

{% endblock %}

1 comment on commit d215c36

@KalobTaulien

This comment has been minimized.

Please sign in to comment.
You can’t perform that action at this time.