Skip to content

Commit

Permalink
Add video block
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Jan 10, 2021
1 parent 4649de4 commit 00b70dc
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mpicms/base/blocks.py
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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')
Expand Down

0 comments on commit 00b70dc

Please sign in to comment.