From 1481c3182b592b026cd850543a718c75bc2bccb3 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Sun, 10 Jan 2021 16:25:00 +0100 Subject: [PATCH] Add video block --- mpicms/base/blocks.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mpicms/base/blocks.py b/mpicms/base/blocks.py index 41dee5f..c23927d 100644 --- a/mpicms/base/blocks.py +++ b/mpicms/base/blocks.py @@ -1,9 +1,11 @@ from django.utils.translation import gettext_lazy as _ +from django.utils.functional import cached_property from wagtail.core import blocks from wagtail.snippets.blocks import SnippetChooserBlock from wagtail.contrib.table_block.blocks import TableBlock as WagtailTableBlock - +import wagtailvideos.models +import wagtailvideos.widgets class ContactBlock(blocks.StructBlock): contact = SnippetChooserBlock('personal.Contact', label=_("Contact")) @@ -24,11 +26,27 @@ class Meta: # noqa template = 'base/blocks/table_block.html' +class VideoBlock(blocks.ChooserBlock): + @cached_property + def target_model(self): + return wagtailvideos.models.Video + + @cached_property + def widget(self): + return wagtailvideos.widgets.AdminVideoChooser + + def render_basic(self, value, context=None): + return value.video_tag(attrs={"controls": True}) if value else "" + + class Meta: + icon = "fa-play" + class ContentBlock(blocks.StreamBlock): richtext = blocks.RichTextBlock(label=_('Editor')) markdown = MarkdownBlock(label=_('Raw Markdown')) table = TableBlock(label=_('Table')) contact = ContactBlock(label=_('Contact')) + video = VideoBlock(label=_('Video')) class Meta: # noqa label = _('content')