Skip to content

Commit 46a811d

Browse files
authored
Home page blocks (#169)
* WIP: Implement override image block. Implemented an override image block but it currently only works for the single column. The single column behaves completely differently from the two columns and three columns. I will revist this. * WIP: No image center div When there is no image, center the div and span the entire row. Ideally give options. * fix: Implement image override for multiple columns Implemented the image override feature for all column types. This was done by passing an image value to the child elements. * chore: Remove todo Removed a todo message. * fix: Add override headline to template Fixed the issue of no override ability for titles in headlines. The template was missing the switches on the headlines.
1 parent f55a395 commit 46a811d

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

home/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from wagtail.core.fields import StreamField
33
from wagtail.admin.edit_handlers import StreamFieldPanel
44
from wagtail.core import blocks
5+
from wagtail.images.blocks import ImageChooserBlock
56

67
from core.models import ArticlePage, ArticlesIndexPage, AdBlock, MarqueeBlock
78

@@ -11,8 +12,12 @@ class ArticleBlock(blocks.StructBlock):
1112
headline = blocks.RichTextBlock(
1213
help_text="Optional. Will override the article's headline.", required=False
1314
)
14-
# TODO: add a photo override block
15-
# TODO: add a "hide photo" block
15+
16+
# Image override block.
17+
image = ImageChooserBlock(
18+
help_text="Optional. Ovverides the image on the post.",
19+
required=False
20+
)
1621

1722
class Meta:
1823
template = "home/article_block.html"

home/templates/home/article.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
<div class="flex-md-row">
44
<div class="d-flex flex-column align-items-start">
5-
{% if article.featured_image %}
6-
{% image article.featured_image width-1200 as photo %}
5+
{% if block_image or article.featured_image %}
6+
{% if block_image %}
7+
{% image block_image width-1200 as photo %}
8+
{% elif article.featured_image %}
9+
{% image article.featured_image width-1200 as photo %}
10+
{% endif %}
711
<a href="{% pageurl article %}">
812
<img class="img-fluid mb-2 mb-md-3" src="{{ photo.url }}">
913
</a>
@@ -12,7 +16,13 @@
1216
<strong class="d-inline-block mb-0 text-primary text-uppercase text-kicker">{{ article.kicker }}</strong>
1317
{% endif %}
1418
<h3 class="mb-2 headline">
15-
<a class="text-dark" href="{% pageurl article %}">{{ article.headline|richtext_unwrapped }}</a>
19+
<a class="text-dark" href="{% pageurl article %}">
20+
{% if block_headline %}
21+
{{ block_headline }}
22+
{% else %}
23+
{{ article.headline|richtext_unwrapped }}
24+
{% endif %}
25+
</a>
1626
</h3>
1727
<div class="card-text mb-auto summary">{{ article.summary|richtext }}</div>
1828
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% load wagtailcore_tags wagtailimages_tags %}
22

3-
{% include "home/article.html" with article=value.article only %}
3+
{% include "home/article.html" with article=value.article block_image=value.image block_headline=value.headline only%}

home/templates/home/home_page.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,37 @@
4343
{% endif %}
4444
{% elif block.block_type == "one_column" %}
4545
<div class="featured border-md-bottom pb-1 mb-5 mb-md-0 d-lg-flex">
46-
<div class="col-lg-7">
46+
{% if block.value.column.image or block.value.column.article.featured_image %}
47+
<div class="col-lg-7">
48+
{% else %}
49+
<div class="col-lg-12">
50+
{% endif %}
4751
{% if block.value.column.article.specific.kicker %}
4852
<strong class="text-primary text-uppercase text-kicker">{{ block.value.column.article.specific.kicker }}</strong>
4953
{% endif %}
5054
<h1 class="display-4 mb-3">
5155
<a class="text-dark" href="{% pageurl block.value.column.article %}">
52-
{{ block.value.column.article.specific.headline|richtext_unwrapped }}
56+
{% if block.value.column.headline %}
57+
{{ block.value.column.headline }}
58+
{% else %}
59+
{{ block.value.column.article.specific.headline|richtext_unwrapped }}
60+
{% endif %}
5361
</a>
5462
</h1>
5563
<div class="lead d-none d-lg-block">{{ block.value.column.article.specific.summary|richtext }}</div>
5664
</div>
65+
{% if block.value.column.image or block.value.column.article.featured_image %}
5766
<div class="col-lg-5">
58-
{% image block.value.column.article.featured_image width-1200 as photo %}
67+
{% if block.value.column.image %}
68+
{% image block.value.column.image width-1200 as photo %}
69+
{% else %}
70+
{% image block.value.column.article.featured_image width-1200 as photo %}
71+
{% endif %}
5972
<a href="{% pageurl block.value.column.article %}">
6073
<img class="img-fluid mb-3" src="{{ photo.url }}">
6174
</a>
6275
</div>
76+
{% endif %}
6377
<div class="col-lg-7 d-lg-none">
6478
<div class="lead">{{ block.value.column.article.specific.summary|richtext }}</div>
6579
</div>

0 commit comments

Comments
 (0)