Make display_name defaulting explicit
This commit is contained in:
@@ -317,7 +317,7 @@ def change_enrollment(request):
|
||||
if not has_access(user, course, 'enroll'):
|
||||
return {'success': False,
|
||||
'error': 'enrollment in {} not allowed at this time'
|
||||
.format(course.lms.display_name)}
|
||||
.format(course.display_name_with_default)}
|
||||
|
||||
org, course_num, run = course_id.split("/")
|
||||
statsd.increment("common.student.enrollment",
|
||||
|
||||
@@ -82,7 +82,7 @@ class XModuleCourseFactory(Factory):
|
||||
|
||||
# This metadata code was copied from cms/djangoapps/contentstore/views.py
|
||||
if display_name is not None:
|
||||
new_course.lms.display_name = display_name
|
||||
new_course.display_name = display_name
|
||||
|
||||
new_course.data_dir = uuid4().hex
|
||||
new_course.lms.start = gmtime()
|
||||
@@ -145,7 +145,7 @@ class XModuleItemFactory(Factory):
|
||||
|
||||
# replace the display name with an optional parameter passed in from the caller
|
||||
if display_name is not None:
|
||||
new_item.lms.display_name = display_name
|
||||
new_item.display_name = display_name
|
||||
|
||||
store.update_metadata(new_item.location.url(), new_item.own_metadata)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def wrap_xmodule(get_html, module, template, context=None):
|
||||
def _get_html():
|
||||
context.update({
|
||||
'content': get_html(),
|
||||
'display_name': module.lms.display_name,
|
||||
'display_name': module.display_name,
|
||||
'class_': module.__class__.__name__,
|
||||
'module_name': module.js_module_name
|
||||
})
|
||||
|
||||
@@ -103,7 +103,7 @@ class AnnotatableModule(XModule):
|
||||
def get_html(self):
|
||||
""" Renders parameters to template. """
|
||||
context = {
|
||||
'display_name': self.display_name,
|
||||
'display_name': self.display_name_with_default,
|
||||
'element_id': self.element_id,
|
||||
'instructions_html': self.instructions,
|
||||
'content_html': self._render_content()
|
||||
|
||||
@@ -367,7 +367,7 @@ class CapaModule(XModule):
|
||||
else:
|
||||
check_button = False
|
||||
|
||||
content = {'name': self.display_name,
|
||||
content = {'name': self.display_name_with_default,
|
||||
'html': html,
|
||||
'weight': self.descriptor.weight,
|
||||
}
|
||||
|
||||
@@ -497,7 +497,7 @@ class MongoModuleStore(ModuleStoreBase):
|
||||
existing_tabs = course.tabs or []
|
||||
existing_tabs.append({
|
||||
'type': 'static_tab',
|
||||
'name': item.lms.display_name,
|
||||
'name': item.display_name,
|
||||
'url_slug': item.location.name
|
||||
})
|
||||
course.tabs = existing_tabs
|
||||
|
||||
@@ -41,7 +41,7 @@ class XModuleCourseFactory(Factory):
|
||||
|
||||
# This metadata code was copied from cms/djangoapps/contentstore/views.py
|
||||
if display_name is not None:
|
||||
new_course.lms.display_name = display_name
|
||||
new_course.display_name = display_name
|
||||
|
||||
new_course.start = gmtime()
|
||||
|
||||
@@ -101,7 +101,7 @@ class XModuleItemFactory(Factory):
|
||||
|
||||
# replace the display name with an optional parameter passed in from the caller
|
||||
if display_name is not None:
|
||||
new_item.lms.display_name = display_name
|
||||
new_item.display_name = display_name
|
||||
|
||||
store.update_metadata(new_item.location.url(), own_metadata(new_item))
|
||||
|
||||
|
||||
@@ -473,7 +473,7 @@ class XMLModuleStore(ModuleStoreBase):
|
||||
if category == "static_tab":
|
||||
for tab in course_descriptor.tabs or []:
|
||||
if tab.get('url_slug') == slug:
|
||||
module.lms.display_name = tab['name']
|
||||
module.display_name = tab['name']
|
||||
module.data_dir = course_dir
|
||||
self.modules[course_descriptor.id][module.location] = module
|
||||
except Exception, e:
|
||||
|
||||
@@ -18,14 +18,6 @@ log = logging.getLogger(__name__)
|
||||
class_priority = ['video', 'problem']
|
||||
|
||||
|
||||
def display_name(module):
|
||||
if hasattr(module, 'display_name'):
|
||||
return module.display_name
|
||||
|
||||
if hasattr(module, 'lms'):
|
||||
return module.lms.display_name
|
||||
|
||||
|
||||
class SequenceModule(XModule):
|
||||
''' Layout module which lays out content in a temporal sequence
|
||||
'''
|
||||
@@ -89,9 +81,9 @@ class SequenceModule(XModule):
|
||||
childinfo = {
|
||||
'content': child.get_html(),
|
||||
'title': "\n".join(
|
||||
display_name(grand_child)
|
||||
grand_child.display_name
|
||||
for grand_child in child.get_children()
|
||||
if display_name(grand_child)
|
||||
if grand_child.display_name is not None
|
||||
),
|
||||
'progress_status': Progress.to_js_status_str(progress),
|
||||
'progress_detail': Progress.to_js_detail_str(progress),
|
||||
@@ -99,7 +91,7 @@ class SequenceModule(XModule):
|
||||
'id': child.id,
|
||||
}
|
||||
if childinfo['title'] == '':
|
||||
childinfo['title'] = display_name(child)
|
||||
childinfo['title'] = child.display_name_with_default
|
||||
contents.append(childinfo)
|
||||
|
||||
params = {'items': contents,
|
||||
|
||||
@@ -243,8 +243,8 @@ class ImportTestCase(BaseCourseTestCase):
|
||||
toy_ch = toy.get_children()[0]
|
||||
two_toys_ch = two_toys.get_children()[0]
|
||||
|
||||
self.assertEqual(toy_ch.lms.display_name, "Overview")
|
||||
self.assertEqual(two_toys_ch.lms.display_name, "Two Toy Overview")
|
||||
self.assertEqual(toy_ch.display_name, "Overview")
|
||||
self.assertEqual(two_toys_ch.display_name, "Two Toy Overview")
|
||||
|
||||
# Also check that the grading policy loaded
|
||||
self.assertEqual(two_toys.grade_cutoffs['C'], 0.5999)
|
||||
@@ -303,7 +303,7 @@ class ImportTestCase(BaseCourseTestCase):
|
||||
cloc = course.location
|
||||
loc = Location(cloc.tag, cloc.org, cloc.course, 'html', 'secret:toylab')
|
||||
html = modulestore.get_instance(course_id, loc)
|
||||
self.assertEquals(html.lms.display_name, "Toy lab")
|
||||
self.assertEquals(html.display_name, "Toy lab")
|
||||
|
||||
def test_url_name_mangling(self):
|
||||
"""
|
||||
|
||||
@@ -142,7 +142,7 @@ class VideoModule(XModule):
|
||||
'position': self.position,
|
||||
'source': self.source,
|
||||
'track': self.track,
|
||||
'display_name': self.display_name,
|
||||
'display_name': self.display_name_with_default,
|
||||
'caption_asset_path': caption_asset_path,
|
||||
'show_captions': self.show_captions,
|
||||
'start': self.start_time,
|
||||
|
||||
@@ -137,7 +137,7 @@ class VideoAlphaModule(XModule):
|
||||
'sub': self.sub,
|
||||
'sources': self.sources,
|
||||
'track': self.track,
|
||||
'display_name': self.display_name,
|
||||
'display_name': self.display_name_with_default,
|
||||
# TODO (cpennington): This won't work when we move to data that isn't on the filesystem
|
||||
'data_dir': getattr(self, 'data_dir', None),
|
||||
'caption_asset_path': caption_asset_path,
|
||||
|
||||
@@ -9,7 +9,7 @@ from pkg_resources import resource_listdir, resource_string, resource_isdir
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
from xblock.core import XBlock
|
||||
from xblock.core import XBlock, Scope, String
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -99,6 +99,12 @@ class XModule(HTMLSnippet, XBlock):
|
||||
# in the module
|
||||
icon_class = 'other'
|
||||
|
||||
display_name = String(
|
||||
help="Display name for this module",
|
||||
scope=Scope.settings,
|
||||
default=None,
|
||||
)
|
||||
|
||||
def __init__(self, system, location, descriptor, model_data):
|
||||
'''
|
||||
Construct a new xmodule
|
||||
@@ -123,6 +129,17 @@ class XModule(HTMLSnippet, XBlock):
|
||||
self._model_data = model_data
|
||||
self._loaded_children = None
|
||||
|
||||
@property
|
||||
def display_name_with_default(self):
|
||||
'''
|
||||
Return a display name for the module: use display_name if defined in
|
||||
metadata, otherwise convert the url name.
|
||||
'''
|
||||
name = self.display_name
|
||||
if name is None:
|
||||
name = self.url_name.replace('_', ' ')
|
||||
return name
|
||||
|
||||
def get_children(self):
|
||||
'''
|
||||
Return module instances for all the children of this module.
|
||||
@@ -335,6 +352,12 @@ class XModuleDescriptor(HTMLSnippet, ResourceTemplates, XBlock):
|
||||
FoldIt, which posts grade-changing updates through a separate API.
|
||||
"""
|
||||
|
||||
display_name = String(
|
||||
help="Display name for this module",
|
||||
scope=Scope.settings,
|
||||
default=None,
|
||||
)
|
||||
|
||||
# ============================= STRUCTURAL MANIPULATION ===================
|
||||
def __init__(self,
|
||||
system,
|
||||
@@ -365,6 +388,17 @@ class XModuleDescriptor(HTMLSnippet, ResourceTemplates, XBlock):
|
||||
|
||||
self._child_instances = None
|
||||
|
||||
@property
|
||||
def display_name_with_default(self):
|
||||
'''
|
||||
Return a display name for the module: use display_name if defined in
|
||||
metadata, otherwise convert the url name.
|
||||
'''
|
||||
name = self.display_name
|
||||
if name is None:
|
||||
name = self.url_name.replace('_', ' ')
|
||||
return name
|
||||
|
||||
def get_required_module_descriptors(self):
|
||||
"""Returns a list of XModuleDescritpor instances upon which this module depends, but are
|
||||
not children of this module"""
|
||||
|
||||
Reference in New Issue
Block a user