-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TWE-1 - BE - New homepage hero fields (#313)
* Add new fields, remove introduction * Make migrations * Display the new fields in the homepage * Update HomePageFactory * Update homepage factory * Fix pattern library YAML file * Convert b & i tags into span tags * Add unit tests for the link converter
- Loading branch information
1 parent
8f1434a
commit 4400045
Showing
10 changed files
with
155 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tbx/core/migrations/0039_remove_homepage_introduction_homepage_hero_heading_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.2.16 on 2024-12-04 08:04 | ||
|
||
from django.db import migrations, models | ||
import wagtail.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("torchbox", "0038_update_theme_colour_choices"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="homepage", | ||
name="introduction", | ||
), | ||
migrations.AddField( | ||
model_name="homepage", | ||
name="hero_heading_1", | ||
field=models.CharField(default="", max_length=255), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="homepage", | ||
name="hero_heading_2", | ||
field=models.CharField(default="", max_length=255), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="homepage", | ||
name="hero_introduction", | ||
field=wagtail.fields.RichTextField(blank=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase | ||
|
||
from ..utils.formatting import ( | ||
convert_bold_links_to_pink, | ||
convert_italic_links_to_purple, | ||
) | ||
|
||
|
||
class ConvertBoldLinksToPinkTestCase(TestCase): | ||
def test_doesnt_convert_non_link(self): | ||
html_text = "<b>Hello</b> world <b><i>foo</i></b> bar" | ||
result = convert_bold_links_to_pink(html_text) | ||
self.assertEqual(html_text, result) | ||
|
||
def test_convert_link(self): | ||
html_text = '<a href="#"><b>Hello</b> world <b><i>foo</i></b> bar</a>' | ||
result = convert_bold_links_to_pink(html_text) | ||
self.assertEqual( | ||
result, | ||
( | ||
'<a href="#"><span class="text-coral">Hello</span> world ' | ||
'<span class="text-coral"><i>foo</i></span> bar</a>' | ||
), | ||
) | ||
|
||
|
||
class ConvertItalicLinksToPurpleTestCase(TestCase): | ||
def test_doesnt_convert_non_link(self): | ||
html_text = "<i>Hello</i> world <b><i>foo</i></b> bar" | ||
result = convert_italic_links_to_purple(html_text) | ||
self.assertEqual(html_text, result) | ||
|
||
def test_convert_link(self): | ||
html_text = '<a href="#"><i>Hello</i> world <b><i>foo</i></b> bar</a>' | ||
result = convert_italic_links_to_purple(html_text) | ||
self.assertEqual( | ||
result, | ||
( | ||
'<a href="#"><span class="text-nebuline">Hello</span> world ' | ||
'<b><span class="text-nebuline">foo</span></b> bar</a>' | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def convert_bold_links_to_pink(html_text): | ||
"""Convert <b> tags inside links into <span class="text-coral">.""" | ||
soup = BeautifulSoup(html_text, "html.parser") | ||
# Limit the changes to anchor tags (<a>). | ||
for anchor_tag in soup.find_all("a"): | ||
# Find all bold tags (<b>) and convert them to span tags (<span>). | ||
for bold_tag in anchor_tag.find_all("b"): | ||
tag_content = "".join([str(c) for c in bold_tag.contents]) | ||
html_text = html_text.replace( | ||
str(bold_tag), f'<span class="text-coral">{tag_content}</span>' | ||
) | ||
return html_text | ||
|
||
|
||
def convert_italic_links_to_purple(html_text): | ||
"""Convert <i> tags inside links into <span class="text-nebuline">.""" | ||
soup = BeautifulSoup(html_text, "html.parser") | ||
# Limit the changes to anchor tags (<a>). | ||
for anchor_tag in soup.find_all("a"): | ||
# Find all italic tags (<i>) and convert them to span tags (<span>). | ||
for italic_tag in anchor_tag.find_all("i"): | ||
tag_content = "".join([str(c) for c in italic_tag.contents]) | ||
html_text = html_text.replace( | ||
str(italic_tag), f'<span class="text-nebuline">{tag_content}</span>' | ||
) | ||
return html_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
tbx/project_styleguide/templates/patterns/molecules/home-page-hero/home-page-hero.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tbx/project_styleguide/templates/patterns/molecules/home-page-hero/home-page-hero.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
context: | ||
page: | ||
title: We amplify the impact of organisations improve people's lives and our planet. | ||
introduction: At Torchbox, we partner with organisations dedicated to bettering lives and the environment, using digital innovation to maximise their positive impact. | ||
hero_heading_1: The digital partner | ||
hero_heading_2: for positive change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tbx/project_styleguide/templates/patterns/pages/home/home_page.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters