feat: add organization logo to public video page (#31922)

* feat: add org logo to public video page

Refactors CTA banner slightly to allow for left org logo float.

* fix: hide org logo if not provided

* test: add tests for org logo
This commit is contained in:
Nathan Sprenkle
2023-03-16 10:35:02 -04:00
committed by GitHub
parent b6ba32830a
commit 4d999ed3f7
4 changed files with 61 additions and 3 deletions

View File

@@ -3096,6 +3096,41 @@ class TestRenderPublicVideoXBlock(TestBasePublicVideoXBlock):
self.assertEqual(expected_status_code, response.status_code)
self.assertEqual(expected_status_code, embed_response.status_code)
def test_get_org_logo_none(self):
# Given a course with no organizational logo
self.setup_course()
target_video = self.video_block_public
# When I render the page
response = self.get_response(usage_key=target_video.location, is_embed=False)
content = response.content.decode('utf-8')
# Then the page does not render an org logo
org_logo = re.search('<img .*class=[\'"]org-logo[\'"].*>', content)
self.assertIsNone(org_logo)
@patch('lms.djangoapps.courseware.views.views.get_course_organization')
def test_get_org_logo(self, mock_get_org):
# Given a course with an organizational logo
self.setup_course()
target_video = self.video_block_public
mock_org_logo_url = "/assets/foo"
mock_org_logo = MagicMock()
mock_org_logo.url = mock_org_logo_url
mock_get_org.return_value = {
"logo": mock_org_logo
}
# When I render the page
response = self.get_response(usage_key=target_video.location, is_embed=False)
content = response.content.decode('utf-8')
# Then the page does render an org logo
org_logo = re.search(f'<img .*class=[\'"]org-logo[\'"].*src=[\'"]{mock_org_logo_url}[\'"].*>', content)
self.assertIsNotNone(org_logo)
class TestRenderXBlockSelfPaced(TestRenderXBlock): # lint-amnesty, pylint: disable=test-inherits-tests
"""

View File

@@ -38,6 +38,7 @@ from markupsafe import escape
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from openedx_filters.learning.filters import CourseAboutRenderStarted
from organizations.api import get_course_organization
from pytz import UTC
from requests.exceptions import ConnectionError, Timeout # pylint: disable=redefined-builtin
from rest_framework import status
@@ -1785,9 +1786,11 @@ class PublicVideoXBlockView(BasePublicVideoXBlockView):
})
course_about_page_url, enroll_url = self.get_public_video_cta_button_urls(course)
social_sharing_metadata = self.get_social_sharing_metadata(course, video_block)
org_logo = self.get_organization_logo_from_course(course)
context = {
'fragment': fragment,
'course': course,
'org_logo': org_logo,
'social_sharing_metadata': social_sharing_metadata,
'learn_more_url': course_about_page_url,
'enroll_url': enroll_url,
@@ -1799,6 +1802,16 @@ class PublicVideoXBlockView(BasePublicVideoXBlockView):
}
return 'public_video.html', context
def get_organization_logo_from_course(self, course):
"""
Get organization logo for this course
"""
course_org = get_course_organization(course.id)
if course_org and course_org['logo']:
return course_org['logo'].url
return None
def get_social_sharing_metadata(self, course, video_block):
"""
Gather the information for the meta OpenGraph and Twitter-specific tags

View File

@@ -516,9 +516,16 @@
// AU 972 Social Video Sharing Page
.public-video-share-cta {
position: relative;
float: right;
z-index: 1;
.org-logo{
height: 40px;
}
.nav-links{
float: right;
}
.btn-learn-more{
@extend %btn-shims;
color: #00262B;

View File

@@ -21,8 +21,11 @@ from django.utils.translation import gettext as _
</%block>
<%block name="body_extra">
<nav class="public-video-share-cta nav-links" aria-label="Learn More">
<div>
<nav class="public-video-share-cta" aria-label="Learn More">
% if org_logo:
<img class="org-logo" src="${org_logo}" alt="Organization Logo"/>
% endif
<div class="nav-links">
<a class="btn-learn-more btn" href="${learn_more_url}">
${_("Learn more about this course")}
</a>