Commit fdf7d331 by gradyward

Reverted to some of the old logic now that we are not using codemirror

parent d3729038
......@@ -133,8 +133,8 @@ DEFAULT_ASSESSMENT_MODULES = [
]
DEFAULT_EDITOR_ASSESSMENTS_ORDER = [
"example-based-assessment",
"student-training",
"peer-assessment",
"self-assessment",
"example-based-assessment"
"self-assessment"
]
......@@ -205,32 +205,4 @@ describe("OpenAssessment.StudioView", function() {
}
});
});
it("installs checkbox listeners with callback", function () {
this.funct = function(){};
spyOn(this, 'funct');
var toggler = new OpenAssessment.ToggleControl(
view.element,
"#ai_assessment_description_closed",
"#ai_assessment_settings_editor"
);
toggler.show();
toggler.hide();
expect(this.funct.calls.length).toEqual(0);
toggler = new OpenAssessment.ToggleControl(
view.element,
"#ai_assessment_description_closed",
"#ai_assessment_settings_editor",
this.funct
);
toggler.show();
toggler.hide();
expect(this.funct.calls.length).toEqual(2);
});
});
......@@ -372,20 +372,12 @@ OpenAssessment.EditExampleBasedAssessmentView = function(element) {
this.element = element;
this.name = "example-based-assessment";
this.codeBox = CodeMirror.fromTextArea(
$(element).find('#ai_training_examples').first().get(0),
{mode: "xml", lineNumbers: true, lineWrapping: true}
);
var view = this;
new OpenAssessment.ToggleControl(
this.element,
"#ai_assessment_description_closed",
"#ai_assessment_settings_editor",
function () {
view.codeBox.refresh();
}
"#ai_assessment_settings_editor"
).install("#include_ai_assessment");
};
......
......@@ -21,7 +21,6 @@ OpenAssessment.Fields = {
/**
Show and hide elements based on a checkbox.
Optionally includes a function to call when the checkbox is changed.
Args:
element (DOM element): The parent element, used to scope the selectors.
......@@ -29,18 +28,11 @@ Args:
to show when the checkbox is in the "off" state.
shownSelector (string): The CSS selector string for elements
to show when the checkbox is in the "on" state.
updateFunction (function): OPTIONAL (defaults to function(){})
a parameter-less function to execute after control has been toggled
**/
OpenAssessment.ToggleControl = function(element, hiddenSelector, shownSelector, updateFunction) {
OpenAssessment.ToggleControl = function(element, hiddenSelector, shownSelector) {
this.element = element;
this.hiddenSelector = hiddenSelector;
this.shownSelector = shownSelector;
if (typeof updateFunction === "undefined"){
this.updateFunction = function () {};
} else {
this.updateFunction = updateFunction;
}
};
OpenAssessment.ToggleControl.prototype = {
......@@ -68,13 +60,11 @@ OpenAssessment.ToggleControl.prototype = {
show: function() {
$(this.hiddenSelector, this.element).addClass('is--hidden');
$(this.shownSelector, this.element).removeClass('is--hidden');
this.updateFunction();
},
hide: function() {
$(this.hiddenSelector, this.element).removeClass('is--hidden');
$(this.shownSelector, this.element).addClass('is--hidden');
this.updateFunction();
}
};
......
......@@ -17,7 +17,7 @@ from openassessment.xblock.validation import validator
from openassessment.xblock.data_conversion import create_rubric_dict, make_django_template_key
from openassessment.xblock.schema import EDITOR_UPDATE_SCHEMA
from openassessment.xblock.resolve_dates import resolve_dates
from openassessment.xblock.xml import serialize_examples_to_xml_str, parse_examples_from_xml_str
logger = logging.getLogger(__name__)
......@@ -144,8 +144,9 @@ class StudioMixin(object):
logger.exception('Editor context is invalid')
return {'success': False, 'msg': _('Error updating XBlock configuration')}
# Check that the editor assessment order contains all the assessments
if set(DEFAULT_EDITOR_ASSESSMENTS_ORDER) != set(data['editor_assessments_order']):
# Check that the editor assessment order contains all the assessments. We are more flexible on example-based.
if (set(DEFAULT_EDITOR_ASSESSMENTS_ORDER) - {'example-based-assessment'}) \
!= (set(data['editor_assessments_order']) - {'example-based-assessment'}):
logger.exception('editor_assessments_order does not contain all expected assessment types')
return {'success': False, 'msg': _('Error updating XBlock configuration')}
......@@ -162,6 +163,12 @@ class StudioMixin(object):
if 'name' not in option:
option['name'] = uuid4().hex
# If example based assessment is enabled, we replace it's xml definition with the dictionary
# definition we expect for validation and storing.
for assessment in data['assessments']:
if assessment['name'] == 'example-based-assessment':
assessment['examples'] = parse_examples_from_xml_str(assessment['examples'])
xblock_validator = validator(self)
success, msg = xblock_validator(
create_rubric_dict(data['prompt'], data['criteria']),
......@@ -260,6 +267,13 @@ class StudioMixin(object):
else:
assessments['training'] = {'examples': [student_training_template], 'template': student_training_template}
example_based_assessment = self.get_assessment_module('example-based-assessment')
if example_based_assessment:
assessments['example_based_assessment'] = {
'examples': serialize_examples_to_xml_str(example_based_assessment)
}
return assessments
def _editor_assessments_order_context(self):
......@@ -285,7 +299,7 @@ class StudioMixin(object):
if asmnt_name in order
]
if problem_order_indices != sorted(problem_order_indices):
unused_assessments = list(set(DEFAULT_EDITOR_ASSESSMENTS_ORDER) - set(used_assessments))
unused_assessments = list(set(DEFAULT_EDITOR_ASSESSMENTS_ORDER) - {'example-based-assessment'} - set(used_assessments))
return sorted(unused_assessments) + used_assessments
# Forwards compatibility:
......
......@@ -18,7 +18,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": "2014-02-27T09:46",
"submission_start": "2014-02-10T09:46"
},
......@@ -45,7 +45,7 @@
"explanation": "Yes explanation"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"feedback": "optional"
}
],
......@@ -108,7 +108,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": "2014-02-27T09:46",
"submission_start": "2014-02-10T09:46"
},
......@@ -154,7 +154,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_start": "2014-02-10T09:46"
},
......@@ -199,7 +199,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": "2012-02-27T09:46",
"submission_start": "2015-02-10T09:46",
"expected_error": "the start date '2015-02-10 09:46:00+00:00' cannot be later than the due date '2012-02-27 09:46:00+00:00'"
......@@ -246,7 +246,7 @@
"due": "2003-01-02T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": "2012-02-27T09:46",
"submission_start": null,
"expected_error": "cannot be later"
......@@ -286,7 +286,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -324,7 +324,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -344,7 +344,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -382,7 +382,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -408,7 +408,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -442,7 +442,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -480,7 +480,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -519,7 +519,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null,
"expected_error": "error updating xblock configuration"
......@@ -559,7 +559,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null,
"expected_error": "error updating xblock configuration"
......@@ -599,7 +599,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"submission_due": null,
"submission_start": null
},
......@@ -652,7 +652,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"student_training_example_missing_options_selected": {
......@@ -701,7 +701,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"student_training_example_missing_criterion": {
......@@ -753,7 +753,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"student_training_example_missing_option": {
......@@ -805,7 +805,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"student_training_no_examples": {
......@@ -850,7 +850,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"expected_error": "you must provide at least one example response for student training"
},
......@@ -903,7 +903,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"],
"expected_error": "example 1 has an extra option"
},
......@@ -995,7 +995,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "self-assessment"]
},
"unrecognized_assessment_in_editor_assessments_order": {
......@@ -1041,10 +1041,6 @@
"due": null
}
],
"editor_assessments_order": [
"student-training", "peer-assessment",
"self-assessment", "example-based-assessment",
"NOT A VALID ASSESSMENT"
]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "NOT A VALID ASSESSMENT"]
}
}
......@@ -42,7 +42,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"unicode": {
......@@ -88,7 +88,7 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"student_training": {
......@@ -149,7 +149,7 @@
"due": "4014-03-10T00:00"
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
},
"already_has_criteria_and_options_names_assigned": {
......@@ -198,6 +198,6 @@
"due": null
}
],
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment", "example-based-assessment"]
"editor_assessments_order": ["student-training", "peer-assessment", "self-assessment"]
}
}
......@@ -24,7 +24,6 @@ class StudioViewTest(XBlockHandlerTestCase):
"allow_file_upload": False,
"assessments": [{"name": "self-assessment"}],
"editor_assessments_order": [
"example-based-assessment",
"student-training",
"peer-assessment",
"self-assessment",
......@@ -117,7 +116,6 @@ class StudioViewTest(XBlockHandlerTestCase):
# Update the XBlock with a different editor assessment order
data = copy.deepcopy(self.UPDATE_EDITOR_DATA)
data['editor_assessments_order'] = [
"example-based-assessment",
"student-training",
"peer-assessment",
"self-assessment",
......
......@@ -803,3 +803,12 @@ def _unicode_to_xml(xml):
return safe_etree.fromstring(xml.encode('utf-8'))
except (ValueError, safe_etree.ParseError):
raise UpdateFromXmlError(_("An error occurred while parsing the XML content."))
def parse_examples_from_xml_str(xml):
examples_root = _unicode_to_xml(xml)
examples = examples_root.findall('example')
return parse_examples_xml(examples)
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