Skip to content
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

CHORE: YouTube Block #1674

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 etna/core/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .quote import QuoteBlock
from .section import SectionBlock, SubHeadingBlock
from .text import InsetTextBlock, WarningTextBlock
from .video import YouTubeBlock

__all__ = [
"APIPageChooserBlock",
Expand Down Expand Up @@ -49,4 +50,5 @@
"SectionDepthAwareStructBlock",
"SubHeadingBlock",
"WarningTextBlock",
"YouTubeBlock",
]
26 changes: 26 additions & 0 deletions etna/core/blocks/video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import re

from django.core.exceptions import ValidationError

from wagtail import blocks

from .image import APIImageChooserBlock


class YouTubeBlock(blocks.StructBlock):
title = blocks.CharBlock(required=True, max_length=100, label="Title")
video_id = blocks.CharBlock(required=True, max_length=11, label="YouTube Video ID")
preview_image = APIImageChooserBlock(
rendition_size="max-640x360", required=False, label="Preview Image"
)

def clean(self, value):
if video_id := value.get("video_id"):
if not re.match(r"^[a-zA-Z0-9_-]{11}$", video_id):
raise ValidationError("Invalid YouTube Video ID")

return super().clean(value)

class Meta:
label = "YouTube Video"
icon = "media"
2 changes: 2 additions & 0 deletions etna/generic_pages/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SectionDepthAwareStructBlock,
SubHeadingBlock,
WarningTextBlock,
YouTubeBlock,
)

from ..media.blocks import MediaBlock
Expand All @@ -37,6 +38,7 @@ class SectionContentBlock(blocks.StreamBlock):
record_links = RecordLinksBlock()
sub_heading = SubHeadingBlock()
warning_text = WarningTextBlock()
youtube_video = YouTubeBlock()


class ContentSectionBlock(SectionDepthAwareStructBlock):
Expand Down
Loading
Loading