Merge pull request #4174 from edx/pmitros/chromeless-xblocks

XBlocks can disable navigation chrome.

This allows for full-screen XBlocks (such as code IDEs), as well as allowing us to somewhat hackishly build top-level XBlocks. This is the first step on the path to non-hackish top-level XBlocks.
This commit is contained in:
Piotr Mitros
2014-06-23 11:56:05 -04:00
7 changed files with 122 additions and 14 deletions

View File

@@ -28,17 +28,38 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.test_course = CourseFactory.create(display_name='Robot_Sub_Course')
self.course = CourseFactory.create(display_name='Robot_Super_Course')
self.chapter0 = ItemFactory.create(parent_location=self.course.location,
self.chapter0 = ItemFactory.create(parent=self.course,
display_name='Overview')
self.chapter9 = ItemFactory.create(parent_location=self.course.location,
self.chapter9 = ItemFactory.create(parent=self.course,
display_name='factory_chapter')
self.section0 = ItemFactory.create(parent_location=self.chapter0.location,
self.section0 = ItemFactory.create(parent=self.chapter0,
display_name='Welcome')
self.section9 = ItemFactory.create(parent_location=self.chapter9.location,
self.section9 = ItemFactory.create(parent=self.chapter9,
display_name='factory_section')
self.unit0 = ItemFactory.create(parent_location=self.section0.location,
self.unit0 = ItemFactory.create(parent=self.section0,
display_name='New Unit')
self.chapterchrome = ItemFactory.create(parent=self.course,
display_name='Chrome')
self.chromelesssection = ItemFactory.create(parent=self.chapterchrome,
display_name='chromeless',
chrome='none')
self.accordionsection = ItemFactory.create(parent=self.chapterchrome,
display_name='accordion',
chrome='accordion')
self.tabssection = ItemFactory.create(parent=self.chapterchrome,
display_name='tabs',
chrome='tabs')
self.defaultchromesection = ItemFactory.create(parent=self.chapterchrome,
display_name='defaultchrome')
self.fullchromesection = ItemFactory.create(parent=self.chapterchrome,
display_name='fullchrome',
chrome='accordion,tabs')
self.tabtest = ItemFactory.create(parent=self.chapterchrome,
display_name='progress_tab',
default_tab = 'progress')
# Create student accounts and activate them.
for i in range(len(self.STUDENT_INFO)):
email, password = self.STUDENT_INFO[i]
@@ -48,6 +69,58 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.staff_user = GlobalStaffFactory()
def assertTabActive(self, tabname, response):
''' Check if the progress tab is active in the tab set '''
for line in response.content.split('\n'):
if tabname in line and 'active' in line:
return
raise AssertionError("assertTabActive failed: "+tabname+" not active")
def assertTabInactive(self, tabname, response):
''' Check if the progress tab is active in the tab set '''
for line in response.content.split('\n'):
if tabname in line and 'active' in line:
raise AssertionError("assertTabInactive failed: "+tabname+" active")
return
def test_chrome_settings(self):
'''
Test settings for disabling and modifying navigation chrome in the courseware:
- Accordion enabled, or disabled
- Navigation tabs enabled, disabled, or redirected
'''
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
test_data = (
('tabs', False, True),
('none', False, False),
('fullchrome', True, True),
('accordion', True, False),
('fullchrome', True, True)
)
for (displayname, accordion, tabs) in test_data:
response = self.client.get(reverse('courseware_section', kwargs={
'course_id': self.course.id.to_deprecated_string(),
'chapter': 'Chrome',
'section': displayname,
}))
self.assertEquals('open_close_accordion' in response.content, accordion)
self.assertEquals('course-tabs' in response.content, tabs)
self.assertTabInactive('progress', response)
self.assertTabActive('courseware', response)
response = self.client.get(reverse('courseware_section', kwargs={
'course_id': self.course.id.to_deprecated_string(),
'chapter': 'Chrome',
'section': 'progress_tab',
}))
self.assertTabActive('progress', response)
self.assertTabInactive('courseware', response)
@override_settings(SESSION_INACTIVITY_TIMEOUT_IN_SECONDS=1)
def test_inactive_session_timeout(self):
"""

View File

@@ -339,6 +339,7 @@ def index(request, course_id, chapter=None, section=None,
if section is not None:
section_descriptor = chapter_descriptor.get_child_by(lambda m: m.location.name == section)
if section_descriptor is None:
# Specifically asked-for section doesn't exist
if masq == 'student': # if staff is masquerading as student be kinder, don't 404
@@ -346,6 +347,17 @@ def index(request, course_id, chapter=None, section=None,
return redirect(reverse('courseware', args=[course.id.to_deprecated_string()]))
raise Http404
## Allow chromeless operation
if section_descriptor.chrome:
chrome = [s.strip() for s in section_descriptor.chrome.lower().split(",")]
if 'accordion' not in chrome:
context['disable_accordion'] = True
if 'tabs' not in chrome:
context['disable_tabs'] = True
if section_descriptor.default_tab:
context['default_tab'] = section_descriptor.default_tab
# cdodge: this looks silly, but let's refetch the section_descriptor with depth=None
# which will prefetch the children more efficiently than doing a recursive load
section_descriptor = modulestore().get_item(section_descriptor.location, depth=None)