Commit d61c91c1 by Calen Pennington

Fix errors around error descriptors and custom tag modules

parent 8693d288
......@@ -22,6 +22,10 @@ log = logging.getLogger(__name__)
class ErrorModule(XModule):
contents = String(scope=Scope.content)
error_msg = String(scope=Scope.content)
def get_html(self):
'''Show an error to staff.
TODO (vshnayder): proper style, divs, etc.
......@@ -29,8 +33,8 @@ class ErrorModule(XModule):
# staff get to see all the details
return self.system.render_template('module-error.html', {
'staff_access': True,
'data': self.definition['data']['contents'],
'error': self.definition['data']['error_msg'],
'data': self.contents,
'error': self.error_msg,
})
......
......@@ -3,25 +3,29 @@ from xmodule.editing_module import XMLEditingDescriptor
from xmodule.xml_module import XmlDescriptor
import logging
import sys
from .model import String, Scope
log = logging.getLogger(__name__)
class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
"""
Module that provides a raw editing view of its data and children. It
requires that the definition xml is valid.
"""
data = String(help="XML data for the module", scope=Scope.content)
@classmethod
def definition_from_xml(cls, xml_object, system):
return {'data': etree.tostring(xml_object, pretty_print=True)}, []
def definition_to_xml(self, resource_fs):
try:
return etree.fromstring(self.definition['data'])
return etree.fromstring(self.data)
except etree.XMLSyntaxError as err:
# Can't recover here, so just add some info and
# re-raise
lines = self.definition['data'].split('\n')
lines = self.data.split('\n')
line, offset = err.position
msg = ("Unable to create xml for problem {loc}. "
"Context: '{context}'".format(
......
......@@ -27,11 +27,6 @@ class CustomTagModule(XModule):
More information given in <a href="/book/234">the text</a>
"""
def __init__(self, system, location, definition, descriptor,
instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition, descriptor,
instance_state, shared_state, **kwargs)
def get_html(self):
return self.descriptor.rendered_html
......@@ -62,14 +57,14 @@ class CustomTagDescriptor(RawDescriptor):
template_loc = self.location._replace(category='custom_tag_template', name=template_name)
template_module = modulestore().get_instance(system.course_id, template_loc)
template_module_data = template_module.definition['data']
template_module_data = template_module.data
template = Template(template_module_data)
return template.render(**params)
@property
def rendered_html(self):
return self.render_template(self.system, self.definition['data'])
return self.render_template(self.system, self.data)
def export_to_file(self):
"""
......
......@@ -143,10 +143,9 @@ def redirect_to_course_position(course_module, first_time):
'chapter': chapter.url_name,
'section': section.url_name}))
def save_child_position(seq_module, child_name, instance_module):
def save_child_position(seq_module, child_name):
"""
child_name: url_name of the child
instance_module: the StudentModule object for the seq_module
"""
for i, c in enumerate(seq_module.get_display_items()):
if c.url_name == child_name:
......@@ -155,8 +154,6 @@ def save_child_position(seq_module, child_name, instance_module):
# Only save if position changed
if position != seq_module.position:
seq_module.position = position
instance_module.state = seq_module.get_instance_state()
instance_module.save()
@login_required
@ensure_csrf_cookie
......@@ -222,8 +219,7 @@ def index(request, course_id, chapter=None, section=None,
chapter_descriptor = course.get_child_by_url_name(chapter)
if chapter_descriptor is not None:
instance_module = get_instance_module(course_id, request.user, course_module, student_module_cache)
save_child_position(course_module, chapter, instance_module)
save_child_position(course_module, chapter)
else:
raise Http404
......@@ -250,8 +246,7 @@ def index(request, course_id, chapter=None, section=None,
raise Http404
# Save where we are in the chapter
instance_module = get_instance_module(course_id, request.user, chapter_module, student_module_cache)
save_child_position(chapter_module, section, instance_module)
save_child_position(chapter_module, section)
context['content'] = section_module.get_html()
......
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