-
Notifications
You must be signed in to change notification settings - Fork 26
Story 2096: Impliment 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
5
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51fe270
Wagtail Integration: Init and Taggable Mixin
jlchilders11 42b596a
Continue work, implement mixins, begin post pages
jlchilders11 0988ce0
Continue work on post pages
jlchilders11 8897110
Implement routing and import script, clean up some additional feature…
jlchilders11 a984bd7
Regeneate migrations
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, | ||
| ) | ||
| 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") | ||
| 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() |
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,108 @@ | ||
| # Generated by Django 6.0.2 on 2026-02-19 22:22 | ||
|
|
||
| import django.db.models.deletion | ||
| import modelcluster.fields | ||
| import pages.mixins | ||
| import wagtail.contrib.routable_page.models | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ("wagtailcore", "0096_referenceindex_referenceindex_source_object_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="ContentTag", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "name", | ||
| models.CharField(max_length=100, unique=True, verbose_name="name"), | ||
| ), | ||
| ( | ||
| "slug", | ||
| models.SlugField( | ||
| allow_unicode=True, | ||
| max_length=100, | ||
| unique=True, | ||
| verbose_name="slug", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "verbose_name": "content tag", | ||
| "verbose_name_plural": "content tags", | ||
| }, | ||
| ), | ||
| migrations.CreateModel( | ||
| name="RoutableHomePage", | ||
| fields=[ | ||
| ( | ||
| "page_ptr", | ||
| models.OneToOneField( | ||
| auto_created=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| parent_link=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| to="wagtailcore.page", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "abstract": False, | ||
| }, | ||
| bases=( | ||
| wagtail.contrib.routable_page.models.RoutablePageMixin, | ||
| pages.mixins.FlaggedMixin, | ||
| pages.mixins.TaggableMixin, | ||
| "wagtailcore.page", | ||
| ), | ||
| ), | ||
| migrations.CreateModel( | ||
| name="TaggedContent", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.AutoField( | ||
| auto_created=True, | ||
| primary_key=True, | ||
| serialize=False, | ||
| verbose_name="ID", | ||
| ), | ||
| ), | ||
| ( | ||
| "content_object", | ||
| modelcluster.fields.ParentalKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="tagged_items", | ||
| to="wagtailcore.page", | ||
| ), | ||
| ), | ||
| ( | ||
| "tag", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="tagged_content", | ||
| to="pages.contenttag", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "abstract": False, | ||
| }, | ||
| ), | ||
| ] |
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,25 @@ | ||
| # Generated by Django 6.0.2 on 2026-02-20 14:56 | ||
|
|
||
| import modelcluster.contrib.taggit | ||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("pages", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="routablehomepage", | ||
| name="tags", | ||
| field=modelcluster.contrib.taggit.ClusterTaggableManager( | ||
| blank=True, | ||
| help_text="A comma-separated list of tags.", | ||
| through="pages.TaggedContent", | ||
| to="pages.ContentTag", | ||
| verbose_name="Tags", | ||
| ), | ||
| ), | ||
| ] |
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.