-
Notifications
You must be signed in to change notification settings - Fork 26
Story 2096: Implement Wagtail Integration #2100
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
Open
jlchilders11
wants to merge
8
commits into
boostorg:develop
Choose a base branch
from
jlchilders11:jc/wagtail-integration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93e5243
Wagtail Integration: Init and Taggable Mixin
jlchilders11 9e97568
Continue work, implement mixins, begin post pages
jlchilders11 54f12ac
Continue work on post pages
jlchilders11 6f96b35
Implement routing and import script, clean up some additional feature…
jlchilders11 bd274ee
Regeneate migrations
jlchilders11 bd26631
PR feedback
jlchilders11 4c226a7
Extend routability for additional content
jlchilders11 46186e0
Remove Unneeded comment
jlchilders11 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
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
Empty file.
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 @@ | ||
| # Register your models here. |
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,5 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class PagesConfig(AppConfig): | ||
| name = "pages" |
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 wagtail.blocks import CharBlock | ||
| from wagtail.blocks import RichTextBlock | ||
| from wagtail.blocks import StructBlock | ||
| from wagtail.blocks import StreamBlock | ||
| from wagtail.blocks import URLBlock | ||
| from wagtail.embeds.blocks import EmbedBlock | ||
| from wagtail.images.blocks import ImageChooserBlock | ||
| from wagtailmarkdown.blocks import MarkdownBlock | ||
|
|
||
|
|
||
| class CustomVideoBlock(StructBlock): | ||
| video = EmbedBlock() | ||
| thumbnail = ImageChooserBlock() | ||
|
|
||
| class Meta: | ||
| template = "blocks/custom_video_block.html" | ||
|
|
||
|
|
||
| class PollBlock(StreamBlock): | ||
| poll_choice = CharBlock(max_length=200) | ||
|
|
||
|
|
||
| POST_BLOCKS = [ | ||
| ("rich_text", RichTextBlock()), | ||
| ("markdown", MarkdownBlock()), | ||
| ("url", URLBlock()), | ||
| ("video", CustomVideoBlock(label="Video")), | ||
| ("poll", PollBlock()), | ||
| ] |
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,110 @@ | ||
| import djclick as click | ||
| from wagtail.models import Page | ||
| from wagtail.images.models import Image | ||
|
|
||
| from pages.models import PostPage | ||
| from pages.models import PostIndexPage | ||
|
|
||
| from news.models import Video | ||
| from news.models import News | ||
| from news.models import BlogPost | ||
| from news.models import Link | ||
| from news.models import Entry | ||
|
|
||
| from django.template.defaultfilters import urlize | ||
| from django.template.defaultfilters import linebreaks_filter | ||
|
|
||
|
|
||
| def get_or_create_page(entry: Entry, index_page: PostIndexPage) -> PostPage: | ||
| try: | ||
| page = index_page.get_children().get(title=entry.title).specific | ||
| except Page.DoesNotExist: | ||
| page = PostPage( | ||
| title=entry.title, | ||
| first_published_at=entry.publish_at, | ||
| owner=entry.author, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| index_page.add_child(instance=page) | ||
| return page | ||
|
|
||
|
|
||
| def convert_text_content(content: str): | ||
| r_content = content | ||
| r_content = urlize(r_content) | ||
| r_content = linebreaks_filter(r_content) | ||
| return r_content | ||
|
|
||
|
|
||
| def convert_image(entry: Entry, post_page: PostPage): | ||
| image = entry.image | ||
| wagtail_image, _ = Image.objects.get_or_create( | ||
| title=image.name, | ||
| defaults={"width": image.width, "height": image.height, "file": image}, | ||
| ) | ||
| post_page.image = wagtail_image | ||
| post_page.save() | ||
|
|
||
|
|
||
| def basic_conversion(entry: Entry, index_page: PostIndexPage): | ||
| print(f"Creating or updating PostPage {entry.title}") | ||
| page = get_or_create_page(entry, index_page) | ||
| if entry.image: | ||
| convert_image(entry, page) | ||
| if entry.summary: | ||
| page.summary = entry.summary | ||
| return page | ||
|
|
||
|
|
||
| @click.command() | ||
| def command(): | ||
| post_index_page = PostIndexPage.objects.first() | ||
| if not post_index_page: | ||
| raise Exception( | ||
| "No Post Index Page found. Create one before running this command." | ||
| ) | ||
|
|
||
| blogs_posts = BlogPost.objects.all() | ||
| print(f"Creating or updating {blogs_posts.count()} Blog Posts") | ||
| for bp in blogs_posts: | ||
| page = basic_conversion(bp, post_index_page) | ||
| page.content = [ | ||
| { | ||
| "type": "markdown", | ||
| "value": convert_text_content(bp.content), | ||
| } | ||
| ] | ||
| page.save() | ||
| news_posts = News.objects.all() | ||
| print(f"Creating or updating {news_posts.count()} News Posts") | ||
| for np in news_posts: | ||
| page = basic_conversion(np, post_index_page) | ||
| page.content = [ | ||
| { | ||
| "type": "markdown", | ||
| "value": convert_text_content(np.content), | ||
| } | ||
| ] | ||
| page.save() | ||
| videos = Video.objects.all() | ||
| print(f"Creating or updating {news_posts.count()} Videos") | ||
|
julhoang marked this conversation as resolved.
Outdated
|
||
| for video in videos: | ||
| page = basic_conversion(video, post_index_page) | ||
| page.content = [ | ||
| { | ||
| "type": "video", | ||
| "value": {"video": video.external_url}, | ||
| } | ||
| ] | ||
| page.save() | ||
|
|
||
| links = Link.objects.all() | ||
| print(f"Creating or updating {links.count()} Links") | ||
| for link in links: | ||
| page = basic_conversion(link, post_index_page) | ||
| page.content = [ | ||
| { | ||
| "type": "url", | ||
| "value": link.external_url, | ||
| } | ||
| ] | ||
| page.save() | ||
Oops, something went wrong.
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.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind helping me understand why we need to route the
/newspath via/pageswith Wagtail, instead of being able to navigate to it directly? It seems like we can navigate to http://localhost:8000/outreach/ directly, is it not possible to do the same with/news? Or is the idea here to have Wagtail lives on a separate prefix for development phase til we are ready to replace the legacy path? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Back when this was being made, the idea was to let these exist in a parallel, and eventually move all Wagtail pages under pages for clarity sake. I'm not sure that that paradigm is still relevant, but I do think that future wagtail pages should live under the pages endpoint.