Skip to content
Snippets Groups Projects
Unverified Commit 46956b99 authored by Simon Chen's avatar Simon Chen Committed by GitHub
Browse files

Merge pull request #16671 from proversity-org/proversity/edx-pr-customize-course-info-title

Customize course info title
parents 9cd770a3 99f6d78d
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
"""
Test the course_info xblock
"""
import ddt
import mock
from django.conf import settings
from django.core.urlresolvers import reverse
......@@ -12,6 +13,7 @@ from ccx_keys.locator import CCXLocator
from lms.djangoapps.ccx.tests.factories import CcxFactory
from nose.plugins.attrib import attr
from openedx.core.djangoapps.self_paced.models import SelfPacedConfiguration
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES, override_waffle_flag
from openedx.features.course_experience import UNIFIED_COURSE_TAB_FLAG
from openedx.features.enterprise_support.tests.mixins.enterprise import EnterpriseTestConsentRequired
......@@ -216,58 +218,96 @@ class CourseInfoLastAccessedTestCase(LoginEnrollmentTestCase, ModuleStoreTestCas
@attr(shard=1)
@override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=False)
@ddt.ddt
class CourseInfoTitleTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
"""
Tests of the CourseInfo page title.
Tests of the CourseInfo page title site configuration options.
"""
def setUp(self):
super(CourseInfoTitleTestCase, self).setUp()
self.course = CourseFactory.create()
self.page = ItemFactory.create(
category="course_info", parent_location=self.course.location,
data="OOGIE BLOOGIE", display_name="updates"
self.course = CourseFactory.create(
org="HogwartZ",
number="Potions_3",
display_organization="HogwartsX",
display_coursenumber="Potions101",
display_name="Introduction to Potions"
)
def test_info_title(self):
@ddt.data(
# Default site configuration shows course number, org, and display name as subtitle.
(dict(),
"Welcome to HogwartsX's Potions101!", "Introduction to Potions"),
# Show org in title
(dict(COURSE_HOMEPAGE_INVERT_TITLE=False,
COURSE_HOMEPAGE_SHOW_SUBTITLE=True,
COURSE_HOMEPAGE_SHOW_ORG=True),
"Welcome to HogwartsX's Potions101!", "Introduction to Potions"),
# Don't show org in title
(dict(COURSE_HOMEPAGE_INVERT_TITLE=False,
COURSE_HOMEPAGE_SHOW_SUBTITLE=True,
COURSE_HOMEPAGE_SHOW_ORG=False),
"Welcome to Potions101!", "Introduction to Potions"),
# Hide subtitle and org
(dict(COURSE_HOMEPAGE_INVERT_TITLE=False,
COURSE_HOMEPAGE_SHOW_SUBTITLE=False,
COURSE_HOMEPAGE_SHOW_ORG=False),
"Welcome to Potions101!", None),
# Show display name as title, hide subtitle and org.
(dict(COURSE_HOMEPAGE_INVERT_TITLE=True,
COURSE_HOMEPAGE_SHOW_SUBTITLE=False,
COURSE_HOMEPAGE_SHOW_ORG=False),
"Welcome to Introduction to Potions!", None),
# Show display name as title with org, hide subtitle.
(dict(COURSE_HOMEPAGE_INVERT_TITLE=True,
COURSE_HOMEPAGE_SHOW_SUBTITLE=False,
COURSE_HOMEPAGE_SHOW_ORG=True),
"Welcome to HogwartsX's Introduction to Potions!", None),
# Show display name as title, hide org, and show course number as subtitle.
(dict(COURSE_HOMEPAGE_INVERT_TITLE=True,
COURSE_HOMEPAGE_SHOW_SUBTITLE=True,
COURSE_HOMEPAGE_SHOW_ORG=False),
"Welcome to Introduction to Potions!", 'Potions101'),
# Show display name as title with org, and show course number as subtitle.
(dict(COURSE_HOMEPAGE_INVERT_TITLE=True,
COURSE_HOMEPAGE_SHOW_SUBTITLE=True,
COURSE_HOMEPAGE_SHOW_ORG=True),
"Welcome to HogwartsX's Introduction to Potions!", 'Potions101'),
)
@ddt.unpack
def test_info_title(self, site_config, expected_title, expected_subtitle):
"""
Test the info page on a course without any display_* settings against
one that does.
Test the info page on a course with all the multiple display options
depeding on the current site configuration
"""
url = reverse('info', args=(unicode(self.course.id),))
response = self.client.get(url)
with with_site_configuration_context(configuration=site_config):
response = self.client.get(url)
content = pq(response.content)
expected_title = "Welcome to {org}'s {course_name}!".format(
org=self.course.display_org_with_default,
course_name=self.course.display_number_with_default
)
display_course = CourseFactory.create(
org="HogwartZ",
number="Potions_3",
display_organization="HogwartsX",
display_coursenumber="Potions",
display_name="Introduction_to_Potions"
)
display_url = reverse('info', args=(unicode(display_course.id),))
display_response = self.client.get(display_url)
display_content = pq(display_response.content)
expected_display_title = "Welcome to {org}'s {course_name}!".format(
org=display_course.display_org_with_default,
course_name=display_course.display_number_with_default
)
self.assertIn(
self.assertEqual(
expected_title,
content('.page-title').contents()[0]
)
self.assertIn(
expected_display_title,
display_content('.page-title').contents()[0]
)
self.assertIn(
display_course.display_name_with_default,
display_content('.page-subtitle').contents()
content('.page-title').contents()[0].strip(),
)
if expected_subtitle is None:
self.assertEqual(
[],
content('.page-subtitle'),
)
else:
self.assertEqual(
expected_subtitle,
content('.page-subtitle').contents()[0].strip(),
)
@override_waffle_flag(UNIFIED_COURSE_TAB_FLAG, active=False)
class CourseInfoTestCaseCCX(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
......
......@@ -373,6 +373,27 @@ def course_info(request, course_id):
# Get the course tools enabled for this user and course
course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key)
course_homepage_invert_title =\
configuration_helpers.get_value(
'COURSE_HOMEPAGE_INVERT_TITLE',
False
)
course_homepage_show_subtitle =\
configuration_helpers.get_value(
'COURSE_HOMEPAGE_SHOW_SUBTITLE',
True
)
course_homepage_show_org =\
configuration_helpers.get_value('COURSE_HOMEPAGE_SHOW_ORG', True)
course_title = course.display_number_with_default
course_subtitle = course.display_name_with_default
if course_homepage_invert_title:
course_title = course.display_name_with_default
course_subtitle = course.display_number_with_default
context = {
'request': request,
'masquerade_user': user,
......@@ -380,6 +401,10 @@ def course_info(request, course_id):
'url_to_enroll': CourseTabView.url_to_enroll(course_key),
'cache': None,
'course': course,
'course_title': course_title,
'course_subtitle': course_subtitle,
'show_subtitle': course_homepage_show_subtitle,
'show_org': course_homepage_show_org,
'staff_access': staff_access,
'masquerade': masquerade,
'supports_preview_menu': True,
......
......@@ -58,8 +58,15 @@ from openedx.core.djangolib.markup import HTML, Text
>
<div class="home">
<div class="page-header-main">
<h2 class="hd hd-2 page-title">${_("Welcome to {org}'s {course_name}!").format(org=course.display_org_with_default, course_name=course.display_number_with_default)}
<div class="page-subtitle">${course.display_name_with_default}</div>
<h2 class="hd hd-2 page-title">
% if show_org:
${_("Welcome to {org}'s {course_title}!").format(org=course.display_org_with_default, course_title=course_title)}
% else:
${_("Welcome to {course_title}!").format(course_title=course_title)}
% endif
% if show_subtitle:
<div class="page-subtitle">${course_subtitle}</div>
% endif
</h2>
</div>
% if resume_course_url and user_is_enrolled:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment