From d61c91c139e58d45723862d15c5d5459bee46b11 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 18 Dec 2012 09:54:25 -0500 Subject: [PATCH] Fix errors around error descriptors and custom tag modules --- common/lib/xmodule/xmodule/error_module.py | 8 ++++++-- common/lib/xmodule/xmodule/raw_module.py | 8 ++++++-- common/lib/xmodule/xmodule/template_module.py | 9 ++------- lms/djangoapps/courseware/views.py | 11 +++-------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/common/lib/xmodule/xmodule/error_module.py b/common/lib/xmodule/xmodule/error_module.py index 67b52d383c..37e98b5b77 100644 --- a/common/lib/xmodule/xmodule/error_module.py +++ b/common/lib/xmodule/xmodule/error_module.py @@ -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, }) diff --git a/common/lib/xmodule/xmodule/raw_module.py b/common/lib/xmodule/xmodule/raw_module.py index bdbc049712..5e50bdf6a0 100644 --- a/common/lib/xmodule/xmodule/raw_module.py +++ b/common/lib/xmodule/xmodule/raw_module.py @@ -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( diff --git a/common/lib/xmodule/xmodule/template_module.py b/common/lib/xmodule/xmodule/template_module.py index f14254c011..988aaaf7b7 100644 --- a/common/lib/xmodule/xmodule/template_module.py +++ b/common/lib/xmodule/xmodule/template_module.py @@ -27,11 +27,6 @@ class CustomTagModule(XModule): More information given in the text """ - 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): """ diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 0c6e2245b9..7ed0685704 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -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()