Skip to content

Commit

Permalink
Merge pull request #19 from open-craft/gabor/ability-to-hide-buttons
Browse files Browse the repository at this point in the history
Options to hide and show download captions and transcript buttons
  • Loading branch information
OmarIthawi authored Sep 20, 2021
2 parents a857f9d + 0a2298d commit 097843a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can get video url for the Xblock directly from your browser's address bar.

![Wistia video URL](doc/img/wistia_video_url.png)

For better students experience make sure all player controls are enabled and video captions are uploaded.
For better students experience make sure all player controls are enabled, video captions, and video transcripts are uploaded.

![Wistia customize video](doc/img/wistia_customize_video.png)

Expand Down
Binary file modified doc/img/wistia_video_edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def package_data(pkg, roots):

setup(
name='wistiavideo-xblock',
version='0.5',
version='1.0.0',
description='wistiavideo XBlock', # TODO: write a better description.
license='GPL v3',
packages=[
Expand Down
4 changes: 2 additions & 2 deletions wistiavideo/static/html/wistiavideo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</div>
<p class="wistia_responsive_download_buttons">
<a href="#" style="display: none;" class="download_button wistia_captions_download" data-api-enabled="{{ has_access_token }}">{{ download_captions_text }}</a>
<a href="#" style="display: none;" class="download_button wistia_transcripts_download" data-api-enabled="{{ has_access_token }}">{{ download_transcripts_text }}</a>
{% if show_captions_download %}<a href="#" style="display: none;" class="download_button wistia_captions_download" data-api-enabled="{{ has_access_token }}">{{ download_captions_text }}</a>{% endif %}
{% if show_transcripts_download %}<a href="#" style="display: none;" class="download_button wistia_transcripts_download">{{ download_transcripts_text }}</a>{% endif %}
</p>
</div>
39 changes: 27 additions & 12 deletions wistiavideo/tests/test_xblock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import unittest

from mock import Mock, patch
Expand Down Expand Up @@ -35,23 +34,31 @@ def test_student_view(self):
student_view_html = xblock.student_view()
self.assertIn(xblock.media_id, student_view_html.body_html())


class WistiaXblockTranscriptsDownloadTests(WistiaXblockBaseTests, unittest.TestCase):
def __render_html(self):
xblock = self.make_xblock()
def __render_html(self, **kwargs):
xblock = self.make_xblock(**kwargs)
return xblock.student_view().body_html()

def test_transcripts_block_exists(self):
self.assertIn("wistia_responsive_download_buttons", self.__render_html())

def test_download_buttons_exist(self):
self.assertIn("wistia_captions_download", self.__render_html())
self.assertIn("wistia_transcripts_download", self.__render_html())
self.assertIn("wistia_captions_download", self.__render_html(show_captions_download=True))
self.assertIn("wistia_transcripts_download", self.__render_html(show_transcripts_download=True))

def test_no_captions_download_button(self):
self.assertNotIn("wistia_captions_download", self.__render_html(show_captions_download=False))

def test_no_transcripts_download_button(self):
self.assertNotIn("wistia_transcripts_download", self.__render_html(show_transcripts_download=False))

def test_access_token_not_set(self):
media_id = "12345abcde"
href = "https://example.wistia.com/medias/{}".format(media_id)

xblock = self.make_xblock(href=href)
xblock = self.make_xblock(
href=href,
show_captions_download=True,
show_transcripts_download=True,
)
rendered_html = xblock.student_view().body_html()

self.assertFalse(xblock.has_access_token)
Expand All @@ -64,7 +71,12 @@ def test_access_token_set(self):
media_id = "12345abcde"
href = "https://example.wistia.com/medias/{}".format(media_id)

xblock = self.make_xblock(href=href, access_token="token")
xblock = self.make_xblock(
href=href,
access_token="token",
show_captions_download=True,
show_transcripts_download=True,
)
rendered_html = xblock.student_view().body_html()

self.assertTrue(xblock.has_access_token)
Expand All @@ -89,7 +101,9 @@ def test_send_request(self, mock_requests):

xblock = self.make_xblock(
href=href,
access_token=expected_token
access_token=expected_token,
show_captions_download=True,
show_transcripts_download=True,
)

response = xblock.download_captions(Mock())
Expand All @@ -107,6 +121,7 @@ def test_send_request(self, mock_requests):
params={"access_token": expected_token}
)


class WistiaXblockValidationTests(WistiaXblockBaseTests, unittest.TestCase):
def test_validate_correct_inputs(self):
xblock = self.make_xblock()
Expand All @@ -124,7 +139,7 @@ def test_validate_correct_inputs(self):
self.assertFalse(validation.add.called)

@patch('xblock.validation.ValidationMessage')
def test_validate_incorrect_inputs(self, ValidationMessage):
def test_validate_incorrect_inputs(self, _):
xblock = self.make_xblock()

data = Mock(href='http://youtube.com/watch?v=something')
Expand Down
38 changes: 30 additions & 8 deletions wistiavideo/wistiavideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pathlib import Path

from xblock.core import XBlock
from xblock.fields import Scope, String
from xblock.fields import Scope, String, Boolean
from xblock.fragment import Fragment
from xblock.validation import ValidationMessage

Expand All @@ -31,21 +31,41 @@
VIDEO_URL_RE = re.compile(r'https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/.*')


class CaptionDownloadMixin:
class AssetsDownloadMixin:
"""
Mixin providing utility functions and handler to download captions from Wistia.
Mixin providing utility functions and handler to download captions and transcripts from Wistia.
The utility mixin is heavily depending on the media ID property provided by the XBlock.
"""

__slots__ = ("media_id",)

access_token = String(
default='',
display_name=_('Wistia API key'),
help=_('The API key related to the account where the video uploaded to.'),
scope=Scope.content,
)

caption_download_editable_fields = ('access_token',)
show_captions_download = Boolean(
default=False,
display_name=_('Captions download button visible'),
help=_('Show download captions button.'),
scope=Scope.content,
)

show_transcripts_download = Boolean(
default=True,
display_name=_('Transcripts download button visible'),
help=_('Show download transcripts button.'),
scope=Scope.content,
)

asset_download_editable_fields = (
'access_token',
'show_captions_download',
'show_transcripts_download',
)

def __send_request(self, url):
"""
Expand Down Expand Up @@ -125,7 +145,7 @@ def download_captions(self, request, suffix=""):
)


class WistiaVideoXBlock(StudioEditableXBlockMixin, CaptionDownloadMixin, XBlock):
class WistiaVideoXBlock(StudioEditableXBlockMixin, AssetsDownloadMixin, XBlock):

display_name = String(
default='Wistia video',
Expand All @@ -142,7 +162,7 @@ class WistiaVideoXBlock(StudioEditableXBlockMixin, CaptionDownloadMixin, XBlock)
)

editable_fields = ('display_name', 'href')
editable_fields += CaptionDownloadMixin.caption_download_editable_fields
editable_fields += AssetsDownloadMixin.asset_download_editable_fields

@property
def media_id(self):
Expand Down Expand Up @@ -175,8 +195,10 @@ def student_view(self, context=None):
context = {
"download_captions_text": _("Download captions"),
"download_transcripts_text": _("Download transcript"),
"media_id": self.media_id,
"has_access_token": self.has_access_token,
"media_id": self.media_id,
"show_captions_download": self.show_captions_download,
"show_transcripts_download": self.show_transcripts_download,
}

frag = Fragment(loader.render_template('static/html/wistiavideo.html', context))
Expand Down

0 comments on commit 097843a

Please sign in to comment.