Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.contrib.routable_page",
"wagtail",
"wagtailmarkdown",
"modelcluster",
Expand All @@ -123,6 +124,7 @@
"slack",
"testimonials",
"patches",
"pages",
"asciidoctor_sandbox",
]

Expand Down
8 changes: 4 additions & 4 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@
),
]
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ [
path("outreach/", include(wagtail_urls)),
path("pages/", include(wagtail_urls)),
Copy link
Copy Markdown
Collaborator

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 /news path via /pages with 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? 🤔

Copy link
Copy Markdown
Collaborator Author

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.

]
+ [
# Libraries docs, some HTML parts are re-written
re_path(
Expand Down Expand Up @@ -440,10 +444,6 @@
),
]
+ djdt_urls
+ [
# Wagtail catch-all (must be last!)
path("", include(wagtail_urls)),
]
)

handler404 = "ak.views.custom_404_view"
5 changes: 4 additions & 1 deletion marketing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class DetailPage(EmailCapturePage):
class OutreachHomePage(Page):
"""A dummy homepage to just return a 404 at the `/outreach/` url"""

parent_page_types = ["wagtailcore.Page"]
parent_page_types = [
"wagtailcore.Page",
"pages.RoutableHomePage",
]
subpage_types = ["marketing.ProgramPageIndex", "marketing.TopicPage"]
max_count = 1 # one container

Expand Down
Empty file added pages/__init__.py
Empty file.
1 change: 1 addition & 0 deletions pages/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
5 changes: 5 additions & 0 deletions pages/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class PagesConfig(AppConfig):
name = "pages"
29 changes: 29 additions & 0 deletions pages/blocks.py
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()),
]
110 changes: 110 additions & 0 deletions pages/management/commands/convert_news_entries.py
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,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also have control over the Updated field?
I think it would be good to populate that as well, so we can order the posts in wagtail as they have been published in the past. I mean, it'd be nice if the order in Wagtail reflected the order in the news/ page.

Image

)
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")
Comment thread
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()
Loading
Loading