-
Notifications
You must be signed in to change notification settings - Fork 4
TWE-1 - BE - New homepage hero fields #313
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
Merged
SharmaineLim
merged 12 commits into
integration/2024-evolution
from
feature/twe-1-homepage-hero-fields
Dec 18, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8811932
Add new fields, remove introduction
SharmaineLim 1a10161
Make migrations
SharmaineLim 51b59e5
Convert markdown to html
SharmaineLim 2d3b23c
Display the new fields in the homepage
SharmaineLim 23e858c
Update HomePageFactory
SharmaineLim 922f859
Replace markdown with 2 fields instead
SharmaineLim 9d0df5b
Update homepage factory
SharmaineLim ddfe5a4
Fix pattern library YAML file
SharmaineLim ebd88f3
Convert b & i tags into span tags
SharmaineLim ddcfcfa
Add comments
SharmaineLim e2c76a3
Add unit tests for the link converter
SharmaineLim 5ce786c
Update migrations
SharmaineLim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.