From b23e55be4012bb7aa9db1f0b1f5f7e9db8115c04 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 24 Dec 2016 23:10:21 +0000 Subject: [PATCH] Add children to section index page --- project/common/models.py | 5 +++-- requirements.txt | 1 + static/src/scss/index.scss | 2 +- templates/pages/section_index_page.html | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/project/common/models.py b/project/common/models.py index aedecd8..bdf14d0 100644 --- a/project/common/models.py +++ b/project/common/models.py @@ -3,6 +3,7 @@ from django.db import models from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel from wagtail.wagtailimages.edit_handlers import ImageChooserPanel from wagtailmetadata.models import MetadataPageMixin +from bs4 import BeautifulSoup class Entity(MetadataPageMixin, Page): @@ -28,8 +29,8 @@ class Entity(MetadataPageMixin, Page): @property def short_body(self): - body_words = str(self.body).split(' ') - return ' '.join(body_words[:30]) # limit to 30 words (ish) + body_words = BeautifulSoup(str(self.body)).get_text().split(' ') + return ' '.join(body_words[:30]) + '...' # limit to 30 words (ish) def get_meta_description(self): return self.search_description or self.short_body diff --git a/requirements.txt b/requirements.txt index e3b4292..3ed99c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ bandit==1.3.0 +beautifulsoup4==4.5.1 bleach==1.5 coverage==4.2 dj_database_url==0.4.1 diff --git a/static/src/scss/index.scss b/static/src/scss/index.scss index 8001082..4973ae9 100644 --- a/static/src/scss/index.scss +++ b/static/src/scss/index.scss @@ -99,7 +99,7 @@ p a { min-width: 100px; height: 100px; - .image { + img { width: 100%; height: 100%; } diff --git a/templates/pages/section_index_page.html b/templates/pages/section_index_page.html index c95bffe..8f73ff2 100644 --- a/templates/pages/section_index_page.html +++ b/templates/pages/section_index_page.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% load wagtailcore_tags %} +{% load wagtailcore_tags wagtailimages_tags %} {% block body_class %}template-indexpage{% endblock %} @@ -17,6 +17,21 @@
+ {% for child in page.get_children.specific %} +
+ +
+ +

{{ child.title }}

+
+

{{ child.get_meta_description }}

+
+
+ {% endfor %}