From f161bdd0a2dfd1ae4d8480e9e415f720df8a0f8e Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Fri, 22 Feb 2013 16:14:46 -0500 Subject: [PATCH] Fix studio import and export for CombinedOpenEnded and PeerGrading XModules Also, fix a bug in the peer grading. --- .../xmodule/combined_open_ended_module.py | 35 ++----------------- .../xmodule/xmodule/peer_grading_module.py | 32 +++++++---------- 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py index ee69d925d0..fdda54bb33 100644 --- a/common/lib/xmodule/xmodule/combined_open_ended_module.py +++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py @@ -4,7 +4,7 @@ from lxml import etree from pkg_resources import resource_string -from .editing_module import EditingDescriptor +from xmodule.raw_module import RawDescriptor from .x_module import XModule from .xml_module import XmlDescriptor from xmodule.open_ended_grading_classes.combined_open_ended_modulev1 import CombinedOpenEndedV1Module, CombinedOpenEndedV1Descriptor @@ -134,7 +134,7 @@ class CombinedOpenEndedModule(XModule): } self.child_descriptor = descriptors[version_index](self.system) - self.child_definition = descriptors[version_index].definition_from_xml(etree.fromstring(definition['xml_string']), self.system) + self.child_definition = descriptors[version_index].definition_from_xml(etree.fromstring(definition['data']), self.system) self.child_module = modules[version_index](self.system, location, self.child_definition, self.child_descriptor, instance_state = json.dumps(instance_state), metadata = self.metadata, static_data= static_data) @@ -165,7 +165,7 @@ class CombinedOpenEndedModule(XModule): return self.child_module.display_name -class CombinedOpenEndedDescriptor(XmlDescriptor, EditingDescriptor): +class CombinedOpenEndedDescriptor(RawDescriptor): """ Module for adding combined open ended questions """ @@ -180,32 +180,3 @@ class CombinedOpenEndedDescriptor(XmlDescriptor, EditingDescriptor): js = {'coffee': [resource_string(__name__, 'js/src/html/edit.coffee')]} js_module_name = "HTMLEditingDescriptor" - @classmethod - def definition_from_xml(cls, xml_object, system): - """ - Pull out the individual tasks, the rubric, and the prompt, and parse - - Returns: - { - 'rubric': 'some-html', - 'prompt': 'some-html', - 'task_xml': dictionary of xml strings, - } - """ - - return {'xml_string' : etree.tostring(xml_object), 'metadata' : xml_object.attrib} - - - def definition_to_xml(self, resource_fs): - '''Return an xml element representing this definition.''' - elt = etree.Element('combinedopenended') - - def add_child(k): - child_str = '<{tag}>{body}'.format(tag=k, body=self.definition[k]) - child_node = etree.fromstring(child_str) - elt.append(child_node) - - for child in ['task']: - add_child(child) - - return elt diff --git a/common/lib/xmodule/xmodule/peer_grading_module.py b/common/lib/xmodule/xmodule/peer_grading_module.py index e262db5615..d1c5c2f85a 100644 --- a/common/lib/xmodule/xmodule/peer_grading_module.py +++ b/common/lib/xmodule/xmodule/peer_grading_module.py @@ -60,6 +60,18 @@ class PeerGradingModule(XModule): if isinstance(self.use_for_single_location, basestring): self.use_for_single_location = (self.use_for_single_location in TRUE_DICT) + self.link_to_location = self.metadata.get('link_to_location', USE_FOR_SINGLE_LOCATION) + if self.use_for_single_location == True: + try: + self.linked_problem = modulestore().get_instance(self.system.course_id, self.link_to_location) + except: + log.error("Linked location {0} for peer grading module {1} does not exist".format( + self.link_to_location, self.location)) + raise + due_date = self.linked_problem.metadata.get('peer_grading_due', None) + if due_date: + self.metadata['due'] = due_date + self.is_graded = self.metadata.get('is_graded', IS_GRADED) if isinstance(self.is_graded, basestring): self.is_graded = (self.is_graded in TRUE_DICT) @@ -75,17 +87,6 @@ class PeerGradingModule(XModule): self.display_due_date = self.timeinfo.display_due_date - self.link_to_location = self.metadata.get('link_to_location', USE_FOR_SINGLE_LOCATION) - if self.use_for_single_location == True: - try: - self.linked_problem = modulestore().get_instance(self.system.course_id, self.link_to_location) - except: - log.error("Linked location {0} for peer grading module {1} does not exist".format( - self.link_to_location, self.location)) - raise - due_date = self.linked_problem.metadata.get('peer_grading_due', None) - if due_date: - self.metadata['due'] = due_date self.ajax_url = self.system.ajax_url if not self.ajax_url.endswith("/"): @@ -606,13 +607,4 @@ class PeerGradingDescriptor(XmlDescriptor, EditingDescriptor): def definition_to_xml(self, resource_fs): '''Return an xml element representing this definition.''' elt = etree.Element('peergrading') - - def add_child(k): - child_str = '<{tag}>{body}'.format(tag=k, body=self.definition[k]) - child_node = etree.fromstring(child_str) - elt.append(child_node) - - for child in ['task']: - add_child(child) - return elt