Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating a generic listing page and blog listing specific page #3427

Merged
merged 22 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 2.2.3 on 2019-07-23 16:43

from django.db import migrations, models
import django.db.models.deletion
import wagtailmetadata.models


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0001_squashed_0021'),
('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'),
('wagtailpages', '0070_auto_20190716_1200'),
]

operations = [
migrations.CreateModel(
name='ListingPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('header', models.CharField(blank=True, max_length=250)),
('header_en', models.CharField(blank=True, max_length=250, null=True)),
('header_de', models.CharField(blank=True, max_length=250, null=True)),
('header_pt', models.CharField(blank=True, max_length=250, null=True)),
('header_es', models.CharField(blank=True, max_length=250, null=True)),
('header_fr', models.CharField(blank=True, max_length=250, null=True)),
('header_pl', models.CharField(blank=True, max_length=250, null=True)),
('intro', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250)),
('intro_en', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('intro_de', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('intro_pt', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('intro_es', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('intro_fr', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('intro_pl', models.CharField(blank=True, help_text='Intro paragraph to show in hero cutout box', max_length=250, null=True)),
('search_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image', verbose_name='Search image')),
],
options={
'abstract': False,
},
bases=(wagtailmetadata.models.MetadataMixin, 'wagtailcore.page', models.Model),
),
migrations.CreateModel(
name='BlogListingPage',
fields=[
('listingpage_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailpages.ListingPage')),
],
options={
'abstract': False,
},
bases=('wagtailpages.listingpage',),
),
]
38 changes: 38 additions & 0 deletions network-api/networkapi/wagtailpages/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from django.db import models
from django.conf import settings
from django.http import HttpResponseRedirect
Expand Down Expand Up @@ -531,6 +532,38 @@ def get_context(self, request):
return get_page_tree_information(self, context)


class ListingPage(FoundationMetadataPageMixin, Page):
"""
This is an abstract page type for creating "listing" pages, e.g.
pages that list "all blog posts" or "all campaigns", etc.
"""

header = models.CharField(
max_length=250,
blank=True
)

intro = models.CharField(
max_length=250,
blank=True,
help_text='Intro paragraph to show in hero cutout box'
)

content_panels = Page.content_panels + [
FieldPanel('header'),
FieldPanel('intro'),
]

def get_context(self, request):
context = super().get_context(request)
try:
PageType = self.model_type
context['entries'] = PageType.objects.all()
except NameError:
context['entries'] = Page.objects.none()
return context


class NewsPage(PrimaryPage):
parent_page_types = ['Homepage']
template = 'wagtailpages/static/news_page.html'
Expand Down Expand Up @@ -591,6 +624,10 @@ def get_context(self, request):
return context


class BlogListingPage(ListingPage):
model_type = BlogPage


class InitiativeSection(models.Model):
page = ParentalKey(
'wagtailpages.InitiativesPage',
Expand Down Expand Up @@ -1085,6 +1122,7 @@ class Homepage(FoundationMetadataPageMixin, Page):
'RedirectingPage',
'OpportunityPage',
'BanneredCampaignPage',
'BlogListingPage',
]

def get_context(self, request):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "./listing_page.html" %}

{% block subcontent %}
{% include "./fragments/blog-cards.html" with entries=entries %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load wagtailcore_tags wagtailimages_tags %}

{% for page in entries %}
<div class="blog-card col-6 col-md-4 my-4">
<div>
<a href={{ page.url }}>
{% image page.get_meta_image fill-400x225 %}
</a>
</div>
<a class="h4-heading d-inline-block my-2" href={{ page.url }}>{{ page.title }}</a>
<p class="body-small">by {{ page.author }} on {{ page.first_published_at|date:"F j, Y" }}</p>
</div>
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ <h1 class="h4-heading">Related content</h2>

<div class="related-posts mb-4">
<div class="row">
{% for page in related_posts %}
<div class="related-card col-6 col-md-4 my-4">
<div>
<a href={{ page.url }}>
{% image page.get_meta_image fill-400x225 %}
</a>
</div>
<a class="h4-heading d-inline-block my-2" href={{ page.url }}>{{ page.title }}</a>
<p class="body-small">by {{ page.author }} on {{ page.first_published_at|date:"F j, Y" }}</p>
</div>
{% endfor %}
{% include "./blog-cards.html" with entries=related_posts %}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "./modular_page.html" %}

{% load wagtailcore_tags mini_site_tags %}


{% block content %}
Pomax marked this conversation as resolved.
Show resolved Hide resolved
{% block minisite_title_mb %}{% endblock %}

{% include "partials/multipage-nav-mobile.html" %}

<div class="container">
<div class="row">
<div class="col-12">
<h1 class="h1-heading mb-0">
{% if root.title %}{{ root.title }}{% elif page.header %}{{ page.header }}{% else %}{{ page.title }}{% endif %}
</h1>
<p class="body-large mt-3 mb-0">{{ page.intro }}</p>
</div>
</div>

<div class="row">
<div class="col-12">
<hr class="intro-and-content-divider">
</div>
</div>

<div class="row">
{% block subcontent %}{% endblock %}
</div>
</div>
{% endblock %}
15 changes: 15 additions & 0 deletions network-api/networkapi/wagtailpages/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ModularPage,
MiniSiteNameSpace,
PrimaryPage,
ListingPage,
NewsPage,
InitiativesPage,
ParticipatePage2,
Expand All @@ -13,6 +14,7 @@
CampaignPage,
OpportunityPage,
BlogPage,
BlogListingPage,

CTA,
Petition,
Expand Down Expand Up @@ -107,6 +109,14 @@ class BanneredCampaignPageTR(TranslationOptions):
)


@register(ListingPage)
class ListingPageTR(TranslationOptions):
fields = (
'header',
'intro',
)


@register(NewsPage)
class NewsPageTR(TranslationOptions):
fields = ()
Expand Down Expand Up @@ -159,3 +169,8 @@ class PeoplePageTR(TranslationOptions):
@register(BlogPage)
class BlogPageTR(TranslationOptions):
fields = ()


@register(BlogListingPage)
class BlogListingPageTR(TranslationOptions):
fields = ()
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.