-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
102 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
# Generated by Django 3.1.5 on 2021-01-21 22:54 | ||
|
||
from django.db import migrations | ||
import wagtail.core.fields | ||
import wagtailvideos.blocks | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='testpage', | ||
name='video_streamfield', | ||
field=wagtail.core.fields.StreamField([('video', wagtailvideos.blocks.VideoChooserBlock())], blank=True), | ||
), | ||
] |
This file contains 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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models | ||
from wagtail.core.models import Page | ||
from wagtail.core.fields import StreamField | ||
from wagtail.admin.edit_handlers import StreamFieldPanel | ||
|
||
from wagtailvideos.edit_handlers import VideoChooserPanel | ||
|
||
from wagtailvideos.blocks import VideoChooserBlock | ||
|
||
class TestPage(Page): | ||
video_field = models.ForeignKey( | ||
'wagtailvideos.Video', related_name='+', null=True, blank=True, on_delete=models.SET_NULL) | ||
|
||
video_streamfield = StreamField([ | ||
('video', VideoChooserBlock()) | ||
], blank=True) | ||
|
||
content_panels = Page.content_panels + [ | ||
VideoChooserPanel('video_field') | ||
VideoChooserPanel('video_field'), | ||
StreamFieldPanel('video_streamfield'), | ||
] |
This file contains 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 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,41 @@ | ||
from wagtail.core.models import Page, Site | ||
from wagtail.tests.utils import WagtailPageTests | ||
from wagtail.tests.utils.form_data import nested_form_data, streamfield | ||
|
||
from tests.app.models import TestPage | ||
from tests.utils import create_test_video_file | ||
from wagtailvideos.models import Video | ||
|
||
|
||
class TestVideoBlock(WagtailPageTests): | ||
def setUp(self): | ||
super().setUp() | ||
self.root_page = Page.objects.get(pk=1) | ||
self.video = Video.objects.create( | ||
title="Test Video", | ||
file=create_test_video_file() | ||
) | ||
|
||
def test_block_admin(self): | ||
self.assertCanCreate(self.root_page, TestPage, nested_form_data({ | ||
'title': 'VideoPage', | ||
'video_streamfield': streamfield([ | ||
('video', self.video.id) | ||
]) | ||
})) | ||
|
||
def test_block_basic_render(self): | ||
page = self.root_page.add_child(instance=TestPage( | ||
title='Test', | ||
slug='vidtest', | ||
video_streamfield=[ | ||
('video', self.video) | ||
] | ||
)) | ||
Site.objects.create( | ||
hostname='localhost', port=8080, root_page=page, | ||
site_name='Test Site', is_default_site=True | ||
) | ||
response = self.client.get(page.full_url) | ||
|
||
self.assertContains(response, self.video.video_tag(attrs={"controls": True})) |
This file contains 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,8 @@ | ||
{% load wagtailvideos_tags %} | ||
<h1>{{ page.title }}</h1> | ||
|
||
{% if self.video_field %} | ||
{% video self.video_field controls %} | ||
{% endif %} | ||
|
||
{{ self.video_streamfield }} |
This file contains 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 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,22 @@ | ||
from wagtail.core.blocks import ChooserBlock | ||
from django.utils.functional import cached_property | ||
|
||
class VideoChooserBlock(ChooserBlock): | ||
@cached_property | ||
def target_model(self): | ||
from wagtailvideos.models import Video | ||
return Video | ||
|
||
@cached_property | ||
def widget(self): | ||
from wagtailvideos.widgets import AdminVideoChooser | ||
return AdminVideoChooser | ||
|
||
def render_basic(self, value, context=None): | ||
if value: | ||
return value.video_tag(attrs={"controls": True}) | ||
else: | ||
return "" | ||
|
||
class Meta: | ||
icon = 'media' |