Introduce constants for studio_view, student_view, and author_view.

This commit is contained in:
cahrens
2014-06-11 14:35:28 -04:00
committed by Andy Armstrong
parent 11c25e8c1a
commit 73e7ced6f9
29 changed files with 128 additions and 96 deletions

View File

@@ -15,6 +15,7 @@ from xmodule.contentstore.content import StaticContent
from xmodule.modulestore.exceptions import ItemNotFoundError
from static_replace import replace_static_urls
from xmodule.modulestore import MONGO_MODULESTORE_TYPE
from xmodule.x_module import STUDENT_VIEW
from courseware.access import has_access
from courseware.model_data import FieldDataCache
@@ -196,7 +197,7 @@ def get_course_about_section(course, section_key):
if about_module is not None:
try:
html = about_module.render('student_view').content
html = about_module.render(STUDENT_VIEW).content
except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None)
log.exception(
@@ -250,7 +251,7 @@ def get_course_info_section(request, course, section_key):
if info_module is not None:
try:
html = info_module.render('student_view').content
html = info_module.render(STUDENT_VIEW).content
except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None)
log.exception(

View File

@@ -12,6 +12,7 @@ from django.conf import settings
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.x_module import STUDENT_VIEW
from courseware.tests import BaseTestXmodule
from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE
@@ -108,7 +109,7 @@ class TestLTI(BaseTestXmodule):
self.addCleanup(patcher.stop)
def test_lti_constructor(self):
generated_content = self.item_descriptor.render('student_view').content
generated_content = self.item_descriptor.render(STUDENT_VIEW).content
expected_content = self.runtime.render_template('lti.html', self.expected_context)
self.assertEqual(generated_content, expected_content)

View File

@@ -22,7 +22,7 @@ from xmodule.lti_module import LTIDescriptor
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import ItemFactory, CourseFactory
from xmodule.x_module import XModuleDescriptor
from xmodule.x_module import XModuleDescriptor, STUDENT_VIEW
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from courseware import module_render as render
@@ -94,7 +94,7 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase):
)
# get the rendered HTML output which should have the rewritten link
html = module.render('student_view').content
html = module.render(STUDENT_VIEW).content
# See if the url got rewritten to the target link
# note if the URL mapping changes then this assertion will break
@@ -416,7 +416,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.course.id,
wrap_xmodule_display=True,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn('div class="xblock xblock-student_view xmodule_display xmodule_HtmlModule"', result_fragment.content)
@@ -429,7 +429,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.course.id,
wrap_xmodule_display=False,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertNotIn('div class="xblock xblock-student_view xmodule_display xmodule_HtmlModule"', result_fragment.content)
@@ -441,7 +441,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn(
'/c4x/{org}/{course}/asset/foo_content'.format(
@@ -459,7 +459,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn(
'/c4x/{org}/{course}/asset/_file.jpg'.format(
@@ -483,7 +483,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.course.id,
static_asset_path="toy_course_dir",
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn('href="/static/toy_course_dir', result_fragment.content)
def test_course_image(self):
@@ -509,7 +509,7 @@ class TestHtmlModifiers(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn(
'/courses/{course_id}/bar/content'.format(
@@ -590,14 +590,14 @@ class MongoViewInStudioTest(ViewInStudioTest):
def test_view_in_studio_link_studio_course(self):
"""Regular Studio courses should see 'View in Studio' links."""
self.setup_mongo_course()
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertIn('View Unit in Studio', result_fragment.content)
def test_view_in_studio_link_only_in_top_level_vertical(self):
"""Regular Studio courses should not see 'View in Studio' for child verticals of verticals."""
self.setup_mongo_course()
# Render the parent vertical, then check that there is only a single "View Unit in Studio" link.
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
# The single "View Unit in Studio" link should appear before the first xmodule vertical definition.
parts = result_fragment.content.split('xmodule_VerticalModule')
self.assertEqual(3, len(parts), "Did not find two vertical modules")
@@ -608,7 +608,7 @@ class MongoViewInStudioTest(ViewInStudioTest):
def test_view_in_studio_link_xml_authored(self):
"""Courses that change 'course_edit_method' setting can hide 'View in Studio' links."""
self.setup_mongo_course(course_edit_method='XML')
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertNotIn('View Unit in Studio', result_fragment.content)
@@ -622,19 +622,19 @@ class MixedViewInStudioTest(ViewInStudioTest):
def test_view_in_studio_link_mongo_backed(self):
"""Mixed mongo courses that are mongo backed should see 'View in Studio' links."""
self.setup_mongo_course()
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertIn('View Unit in Studio', result_fragment.content)
def test_view_in_studio_link_xml_authored(self):
"""Courses that change 'course_edit_method' setting can hide 'View in Studio' links."""
self.setup_mongo_course(course_edit_method='XML')
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertNotIn('View Unit in Studio', result_fragment.content)
def test_view_in_studio_link_xml_backed(self):
"""Course in XML only modulestore should not see 'View in Studio' links."""
self.setup_xml_course()
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertNotIn('View Unit in Studio', result_fragment.content)
@@ -648,7 +648,7 @@ class XmlViewInStudioTest(ViewInStudioTest):
def test_view_in_studio_link_xml_backed(self):
"""Course in XML only modulestore should not see 'View in Studio' links."""
self.setup_xml_course()
result_fragment = self.module.render('student_view')
result_fragment = self.module.render(STUDENT_VIEW)
self.assertNotIn('View Unit in Studio', result_fragment.content)
@@ -694,7 +694,7 @@ class TestStaffDebugInfo(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertNotIn('Staff Debug', result_fragment.content)
def test_staff_debug_info_enabled(self):
@@ -705,7 +705,7 @@ class TestStaffDebugInfo(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertIn('Staff Debug', result_fragment.content)
@patch.dict('django.conf.settings.FEATURES', {'DISPLAY_HISTOGRAMS_TO_STAFF': False})
@@ -717,7 +717,7 @@ class TestStaffDebugInfo(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
result_fragment = module.render('student_view')
result_fragment = module.render(STUDENT_VIEW)
self.assertNotIn('histrogram', result_fragment.content)
def test_histogram_enabled_for_unscored_xmodules(self):
@@ -741,7 +741,7 @@ class TestStaffDebugInfo(ModuleStoreTestCase):
field_data_cache,
self.course.id,
)
module.render('student_view')
module.render(STUDENT_VIEW)
self.assertFalse(mock_grade_histogram.called)
def test_histogram_enabled_for_scored_xmodules(self):
@@ -764,7 +764,7 @@ class TestStaffDebugInfo(ModuleStoreTestCase):
self.field_data_cache,
self.course.id,
)
module.render('student_view')
module.render(STUDENT_VIEW)
self.assertTrue(mock_grade_histogram.called)

View File

@@ -12,6 +12,7 @@ from webob import Request
from xmodule.contentstore.content import StaticContent
from xmodule.contentstore.django import contentstore
from xmodule.modulestore.django import editable_modulestore
from xmodule.x_module import STUDENT_VIEW
from . import BaseTestXmodule
from .test_video_xml import SOURCE_XML
from cache_toolbox.core import del_cached_content
@@ -175,7 +176,7 @@ class TestTranscriptAvailableTranslationsDispatch(TestVideo):
def setUp(self):
super(TestTranscriptAvailableTranslationsDispatch, self).setUp()
self.item_descriptor.render('student_view')
self.item_descriptor.render(STUDENT_VIEW)
self.item = self.item_descriptor.xmodule_runtime.xmodule_instance
self.subs = {"start": [10], "end": [100], "text": ["Hi, welcome to Edx."]}
@@ -234,7 +235,7 @@ class TestTranscriptDownloadDispatch(TestVideo):
def setUp(self):
super(TestTranscriptDownloadDispatch, self).setUp()
self.item_descriptor.render('student_view')
self.item_descriptor.render(STUDENT_VIEW)
self.item = self.item_descriptor.xmodule_runtime.xmodule_instance
def test_download_transcript_not_exist(self):
@@ -299,7 +300,7 @@ class TestTranscriptTranslationGetDispatch(TestVideo):
def setUp(self):
super(TestTranscriptTranslationGetDispatch, self).setUp()
self.item_descriptor.render('student_view')
self.item_descriptor.render(STUDENT_VIEW)
self.item = self.item_descriptor.xmodule_runtime.xmodule_instance
def test_translation_fails(self):
@@ -609,7 +610,7 @@ class TestGetTranscript(TestVideo):
def setUp(self):
super(TestGetTranscript, self).setUp()
self.item_descriptor.render('student_view')
self.item_descriptor.render(STUDENT_VIEW)
self.item = self.item_descriptor.xmodule_runtime.xmodule_instance
def test_good_transcript(self):

View File

@@ -13,6 +13,7 @@ from xblock.field_data import DictFieldData
from xmodule.video_module import create_youtube_string
from xmodule.tests import get_test_descriptor_system
from xmodule.video_module import VideoDescriptor
from xmodule.x_module import STUDENT_VIEW
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from . import BaseTestXmodule
@@ -25,7 +26,7 @@ class TestVideoYouTube(TestVideo):
def test_video_constructor(self):
"""Make sure that all parameters extracted correctly from xml"""
context = self.item_descriptor.render('student_view').content
context = self.item_descriptor.render(STUDENT_VIEW).content
sources = json.dumps([u'example.mp4', u'example.webm'])
expected_context = {
@@ -89,7 +90,7 @@ class TestVideoNonYouTube(TestVideo):
"""Make sure that if the 'youtube' attribute is omitted in XML, then
the template generates an empty string for the YouTube streams.
"""
context = self.item_descriptor.render('student_view').content
context = self.item_descriptor.render(STUDENT_VIEW).content
sources = json.dumps([u'example.mp4', u'example.webm'])
expected_context = {
@@ -231,7 +232,7 @@ class TestGetHtmlMethod(BaseTestXmodule):
self.item_descriptor, 'transcript', 'download'
).rstrip('/?')
context = self.item_descriptor.render('student_view').content
context = self.item_descriptor.render(STUDENT_VIEW).content
expected_context.update({
'transcript_download_format': None if self.item_descriptor.track and self.item_descriptor.download_track else 'srt',
@@ -344,7 +345,7 @@ class TestGetHtmlMethod(BaseTestXmodule):
sources=data['sources']
)
self.initialize_module(data=DATA)
context = self.item_descriptor.render('student_view').content
context = self.item_descriptor.render(STUDENT_VIEW).content
expected_context = dict(initial_context)
expected_context.update({

View File

@@ -5,6 +5,7 @@ import json
from operator import itemgetter
from . import BaseTestXmodule
from xmodule.x_module import STUDENT_VIEW
class TestWordCloud(BaseTestXmodule):
@@ -242,7 +243,7 @@ class TestWordCloud(BaseTestXmodule):
def test_word_cloud_constructor(self):
"""Make sure that all parameters extracted correclty from xml"""
fragment = self.runtime.render(self.item_descriptor, 'student_view')
fragment = self.runtime.render(self.item_descriptor, STUDENT_VIEW)
expected_context = {
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url,

View File

@@ -42,6 +42,7 @@ from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
from xmodule.modulestore.search import path_to_location
from xmodule.tabs import CourseTabList, StaffGradingTab, PeerGradingTab, OpenEndedGradingTab
from xmodule.x_module import STUDENT_VIEW
import shoppingcart
from opaque_keys import InvalidKeyError
@@ -377,7 +378,7 @@ def index(request, course_id, chapter=None, section=None,
# Save where we are in the chapter
save_child_position(chapter_module, section)
context['fragment'] = section_module.render('student_view')
context['fragment'] = section_module.render(STUDENT_VIEW)
context['section_title'] = section_descriptor.display_name_with_default
else:
# section is none, so display a message
@@ -865,7 +866,7 @@ def get_static_tab_contents(request, course, tab):
html = ''
if tab_module is not None:
try:
html = tab_module.render('student_view').content
html = tab_module.render(STUDENT_VIEW).content
except Exception: # pylint: disable=broad-except
html = render_to_string('courseware/error-message.html', None)
log.exception(