Commit b46172da by Victor Shnayder

Rename module.name and descriptor.name to url_name

* update templates and code references
* also a display_name property that defaults to cleaned url_name
parent 2f911fd3
...@@ -108,7 +108,7 @@ def edit_item(request): ...@@ -108,7 +108,7 @@ def edit_item(request):
'contents': item.get_html(), 'contents': item.get_html(),
'js_module': item.js_module_name, 'js_module': item.js_module_name,
'category': item.category, 'category': item.category,
'name': item.name, 'url_name': item.url_name,
'previews': get_module_previews(request, item), 'previews': get_module_previews(request, item),
}) })
......
<section id="unit-wrapper"> <section id="unit-wrapper">
<header> <header>
<section> <section>
<h1 class="editable">${name}</h1> <h1 class="editable">${url_name}</h1>
<p class="${category}"><a href="#">${category}</a></p> <p class="${category}"><a href="#">${category}</a></p>
</section> </section>
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
% for week in weeks: % for week in weeks:
<li class="week" data-id="${week.location.url()}"> <li class="week" data-id="${week.location.url()}">
<header> <header>
<h1><a href="#" class="week-edit">${week.name}</a></h1> <h1><a href="#" class="week-edit">${week.url_name}</a></h1>
<ul> <ul>
% if 'goals' in week.metadata: % if 'goals' in week.metadata:
% for goal in week.metadata['goals']: % for goal in week.metadata['goals']:
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
data-type="${module.js_module_name}" data-type="${module.js_module_name}"
data-preview-type="${module.module_class.js_module_name}"> data-preview-type="${module.module_class.js_module_name}">
<a href="#" class="module-edit">${module.name}</a> <a href="#" class="module-edit">${module.url_name}</a>
<a href="#" class="draggable">handle</a> <a href="#" class="draggable">handle</a>
</li> </li>
% endfor % endfor
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<a href="#" class="module-edit" <a href="#" class="module-edit"
data-id="${child.location.url()}" data-id="${child.location.url()}"
data-type="${child.js_module_name}" data-type="${child.js_module_name}"
data-preview-type="${child.module_class.js_module_name}">${child.name}</a> data-preview-type="${child.module_class.js_module_name}">${child.url_name}</a>
<a href="#" class="draggable">handle</a> <a href="#" class="draggable">handle</a>
</li> </li>
%endfor %endfor
......
...@@ -121,13 +121,13 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): ...@@ -121,13 +121,13 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor):
# Not proper format. Write html to file, return an empty tag # Not proper format. Write html to file, return an empty tag
filepath = u'{category}/{name}.html'.format(category=self.category, filepath = u'{category}/{name}.html'.format(category=self.category,
name=self.name) name=self.url_name)
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(self.definition['data']) file.write(self.definition['data'])
elt = etree.Element('html') elt = etree.Element('html')
elt.set("filename", self.name) elt.set("filename", self.url_name)
return elt return elt
...@@ -87,8 +87,8 @@ def path_to_location(modulestore, location, course_name=None): ...@@ -87,8 +87,8 @@ def path_to_location(modulestore, location, course_name=None):
n = len(path) n = len(path)
course_id = CourseDescriptor.location_to_id(path[0]) course_id = CourseDescriptor.location_to_id(path[0])
chapter = path[1].name if n > 1 else None chapter = path[1].url_name if n > 1 else None
section = path[2].name if n > 2 else None section = path[2].url_name if n > 2 else None
# TODO (vshnayder): not handling position at all yet... # TODO (vshnayder): not handling position at all yet...
position = None position = None
......
...@@ -23,11 +23,12 @@ class VideoModule(XModule): ...@@ -23,11 +23,12 @@ class VideoModule(XModule):
css = {'scss': [resource_string(__name__, 'css/video/display.scss')]} css = {'scss': [resource_string(__name__, 'css/video/display.scss')]}
js_module_name = "Video" js_module_name = "Video"
def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs): def __init__(self, system, location, definition,
XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs) instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition,
instance_state, shared_state, **kwargs)
xmltree = etree.fromstring(self.definition['data']) xmltree = etree.fromstring(self.definition['data'])
self.youtube = xmltree.get('youtube') self.youtube = xmltree.get('youtube')
self.name = xmltree.get('name')
self.position = 0 self.position = 0
if instance_state is not None: if instance_state is not None:
...@@ -71,7 +72,7 @@ class VideoModule(XModule): ...@@ -71,7 +72,7 @@ class VideoModule(XModule):
'streams': self.video_list(), 'streams': self.video_list(),
'id': self.location.html_id(), 'id': self.location.html_id(),
'position': self.position, 'position': self.position,
'name': self.name, 'display_name': self.display_name,
# TODO (cpennington): This won't work when we move to data that isn't on the filesystem # TODO (cpennington): This won't work when we move to data that isn't on the filesystem
'data_dir': self.metadata['data_dir'], 'data_dir': self.metadata['data_dir'],
}) })
......
...@@ -191,11 +191,20 @@ class XModule(HTMLSnippet): ...@@ -191,11 +191,20 @@ class XModule(HTMLSnippet):
self.instance_state = instance_state self.instance_state = instance_state
self.shared_state = shared_state self.shared_state = shared_state
self.id = self.location.url() self.id = self.location.url()
self.name = self.location.name self.url_name = self.location.name
self.category = self.location.category self.category = self.location.category
self.metadata = kwargs.get('metadata', {}) self.metadata = kwargs.get('metadata', {})
self._loaded_children = None self._loaded_children = None
@property
def display_name(self):
'''
Return a display name for the module: use display_name if defined in
metadata, otherwise convert the url name.
'''
return self.metadata.get('display_name',
self.url_name.replace('_', ' '))
def get_children(self): def get_children(self):
''' '''
Return module instances for all the children of this module. Return module instances for all the children of this module.
...@@ -355,7 +364,7 @@ class XModuleDescriptor(Plugin, HTMLSnippet): ...@@ -355,7 +364,7 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
self.metadata = kwargs.get('metadata', {}) self.metadata = kwargs.get('metadata', {})
self.definition = definition if definition is not None else {} self.definition = definition if definition is not None else {}
self.location = Location(kwargs.get('location')) self.location = Location(kwargs.get('location'))
self.name = self.location.name self.url_name = self.location.name
self.category = self.location.category self.category = self.location.category
self.shared_state_key = kwargs.get('shared_state_key') self.shared_state_key = kwargs.get('shared_state_key')
...@@ -363,6 +372,15 @@ class XModuleDescriptor(Plugin, HTMLSnippet): ...@@ -363,6 +372,15 @@ class XModuleDescriptor(Plugin, HTMLSnippet):
self._inherited_metadata = set() self._inherited_metadata = set()
@property @property
def display_name(self):
'''
Return a display name for the module: use display_name if defined in
metadata, otherwise convert the url name.
'''
return self.metadata.get('display_name',
self.url_name.replace('_', ' '))
@property
def own_metadata(self): def own_metadata(self):
""" """
Return the metadata that is not inherited, but was defined on this module. Return the metadata that is not inherited, but was defined on this module.
......
...@@ -225,7 +225,7 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -225,7 +225,7 @@ class XmlDescriptor(XModuleDescriptor):
# Write it to a file if necessary # Write it to a file if necessary
if self.split_to_file(xml_object): if self.split_to_file(xml_object):
# Put this object in its own file # Put this object in its own file
filepath = self.__class__._format_filepath(self.category, self.name) filepath = self.__class__._format_filepath(self.category, self.url_name)
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(etree.tostring(xml_object, pretty_print=True)) file.write(etree.tostring(xml_object, pretty_print=True))
...@@ -238,10 +238,10 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -238,10 +238,10 @@ class XmlDescriptor(XModuleDescriptor):
xml_object.tail = '' xml_object.tail = ''
xml_object.set('filename', self.name) xml_object.set('filename', self.url_name)
# Add the metadata # Add the metadata
xml_object.set('url_name', self.name) xml_object.set('url_name', self.url_name)
for attr in self.metadata_attributes: for attr in self.metadata_attributes:
attr_map = self.xml_attribute_map.get(attr, AttrMap(attr)) attr_map = self.xml_attribute_map.get(attr, AttrMap(attr))
metadata_key = attr_map.metadata_key metadata_key = attr_map.metadata_key
......
...@@ -83,7 +83,7 @@ def get_course_about_section(course, section_key): ...@@ -83,7 +83,7 @@ def get_course_about_section(course, section_key):
log.warning("Missing about section {key} in course {url}".format(key=section_key, url=course.location.url())) log.warning("Missing about section {key} in course {url}".format(key=section_key, url=course.location.url()))
return None return None
elif section_key == "title": elif section_key == "title":
return course.metadata.get('display_name', course.name) return course.metadata.get('display_name', course.url_name)
elif section_key == "university": elif section_key == "university":
return course.location.org return course.location.org
elif section_key == "number": elif section_key == "number":
......
% if name is not UNDEFINED and name is not None: % if name is not UNDEFINED and name is not None:
<h1> ${name} </h1> <h1> ${display_name} </h1>
% endif % endif
<div id="video_${id}" class="video" data-streams="${streams}" data-caption-data-dir="${data_dir}"> <div id="video_${id}" class="video" data-streams="${streams}" data-caption-data-dir="${data_dir}">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment