Commit 645115fb by Tim Krones

Address upstream review comments.

parent 0d4a06ac
...@@ -288,10 +288,10 @@ class TestVectorDraw(StudioEditableBaseTest): ...@@ -288,10 +288,10 @@ class TestVectorDraw(StudioEditableBaseTest):
expected_line_position = position.items() expected_line_position = position.items()
for line in line_elements: for line in line_elements:
line_position = { line_position = {
"x1": int(float(line.get_attribute("x1"))), "x1": int(line.get_attribute("x1").split(".", 1)[0]),
"y1": int(float(line.get_attribute("y1"))), "y1": int(line.get_attribute("y1").split(".", 1)[0]),
"x2": int(float(line.get_attribute("x2"))), "x2": int(line.get_attribute("x2").split(".", 1)[0]),
"y2": int(float(line.get_attribute("y2"))), "y2": int(line.get_attribute("y2").split(".", 1)[0]),
}.items() }.items()
if line_position == expected_line_position: if line_position == expected_line_position:
return line return line
...@@ -300,8 +300,8 @@ class TestVectorDraw(StudioEditableBaseTest): ...@@ -300,8 +300,8 @@ class TestVectorDraw(StudioEditableBaseTest):
expected_position = position.items() expected_position = position.items()
for point in point_elements: for point in point_elements:
point_position = { point_position = {
"cx": int(round(float(point.get_attribute("cx")))), "cx": int(point.get_attribute("cx").split(".", 1)[0]),
"cy": int(round(float(point.get_attribute("cy")))), "cy": int(point.get_attribute("cy").split(".", 1)[0]),
}.items() }.items()
if point_position == expected_position: if point_position == expected_position:
return point return point
...@@ -377,9 +377,9 @@ class TestVectorDraw(StudioEditableBaseTest): ...@@ -377,9 +377,9 @@ class TestVectorDraw(StudioEditableBaseTest):
self.assertTrue(status.is_displayed()) self.assertTrue(status.is_displayed())
correctness = status.find_element_by_css_selector(".correctness") correctness = status.find_element_by_css_selector(".correctness")
if answer_correct: if answer_correct:
self.assertTrue("checkmark-correct fa fa-check" in correctness.get_attribute("class")) self.assertIn("checkmark-correct fa fa-check", correctness.get_attribute("class"))
else: else:
self.assertTrue("checkmark-incorrect fa fa-times" in correctness.get_attribute("class")) self.assertIn("checkmark-incorrect fa fa-times", correctness.get_attribute("class"))
status_message = status.find_element_by_css_selector(".status-message") status_message = status.find_element_by_css_selector(".status-message")
self.assertEquals(status_message.text, expected_message) self.assertEquals(status_message.text, expected_message)
...@@ -915,7 +915,7 @@ class TestVectorDraw(StudioEditableBaseTest): ...@@ -915,7 +915,7 @@ class TestVectorDraw(StudioEditableBaseTest):
self.change_property("tail", "3, 3") self.change_property("tail", "3, 3")
# Check new position: Tail updated, tip updated # Check new position: Tail updated, tip updated
vectors[0]["expected_line_position"] = {'x1': 370, 'y1': 159, 'x2': 425, 'y2': 102} vectors[0]["expected_line_position"] = {'x1': 370, 'y1': 159, 'x2': 425, 'y2': 102}
vectors[0]["expected_tail_position"] = {'cx': 370, 'cy': 159} vectors[0]["expected_tail_position"] = {'cx': 369, 'cy': 158}
vectors[0]["expected_tip_position"] = {'cx': 434, 'cy': 94} vectors[0]["expected_tip_position"] = {'cx': 434, 'cy': 94}
self.assert_vectors(board, vectors) self.assert_vectors(board, vectors)
......
...@@ -99,11 +99,11 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -99,11 +99,11 @@ function VectorDrawXBlock(runtime, element, init_args) {
vectorProperties.attr("id", id + "-vector-properties"); vectorProperties.attr("id", id + "-vector-properties");
// Draw vectors and points // Draw vectors and points
this.settings.points.forEach(function(point, idx) { _.each(this.settings.points, function(point, idx) {
renderAndSetMenuOptions(point, idx, 'point', this); renderAndSetMenuOptions(point, idx, 'point', this);
}, this); }, this);
this.settings.vectors.forEach(function(vec, idx) { _.each(this.settings.vectors, function(vec, idx) {
renderAndSetMenuOptions(vec, idx, 'vector', this); renderAndSetMenuOptions(vec, idx, 'vector', this);
}, this); }, this);
...@@ -210,7 +210,7 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -210,7 +210,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
var lineID = lineElement.attr("id"); var lineID = lineElement.attr("id");
var titleID = lineID + "-title"; var titleID = lineID + "-title";
var titleElement = $("<title>").attr("id", titleID).text(vec.name); var titleElement = $("<title>", {"id": titleID, "text": vec.name});
lineElement.append(titleElement); lineElement.append(titleElement);
lineElement.attr("aria-labelledby", titleID); lineElement.attr("aria-labelledby", titleID);
...@@ -245,7 +245,7 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -245,7 +245,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
selector = selector.split('-'); selector = selector.split('-');
return { return {
type: selector[0], type: selector[0],
idx: parseInt(selector[1]) idx: parseInt(selector[1], 10)
}; };
} }
return {}; return {};
...@@ -513,13 +513,13 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -513,13 +513,13 @@ function VectorDrawXBlock(runtime, element, init_args) {
VectorDraw.prototype.getState = function() { VectorDraw.prototype.getState = function() {
var vectors = {}, points = {}; var vectors = {}, points = {};
this.settings.vectors.forEach(function(vec) { _.each(this.settings.vectors, function(vec) {
var coords = this.getVectorCoords(vec.name); var coords = this.getVectorCoords(vec.name);
if (coords) { if (coords) {
vectors[vec.name] = coords; vectors[vec.name] = coords;
} }
}, this); }, this);
this.settings.points.forEach(function(point) { _.each(this.settings.points, function(point) {
var obj = this.board.elementsByName[point.name]; var obj = this.board.elementsByName[point.name];
if (obj) { if (obj) {
points[point.name] = [obj.X(), obj.Y()]; points[point.name] = [obj.X(), obj.Y()];
...@@ -529,7 +529,7 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -529,7 +529,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
}; };
VectorDraw.prototype.setState = function(state) { VectorDraw.prototype.setState = function(state) {
this.settings.vectors.forEach(function(vec, idx) { _.each(this.settings.vectors, function(vec, idx) {
var vec_state = state.vectors[vec.name]; var vec_state = state.vectors[vec.name];
if (vec_state) { if (vec_state) {
this.renderVector(idx, [vec_state.tail, vec_state.tip]); this.renderVector(idx, [vec_state.tail, vec_state.tip]);
...@@ -537,7 +537,7 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -537,7 +537,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
this.removeVector(idx); this.removeVector(idx);
} }
}, this); }, this);
this.settings.points.forEach(function(point, idx) { _.each(this.settings.points, function(point, idx) {
var point_state = state.points[point.name]; var point_state = state.points[point.name];
if (point_state) { if (point_state) {
this.renderPoint(idx, point_state); this.renderPoint(idx, point_state);
...@@ -567,10 +567,11 @@ function VectorDrawXBlock(runtime, element, init_args) { ...@@ -567,10 +567,11 @@ function VectorDrawXBlock(runtime, element, init_args) {
} }
checks.push(presence_check); checks.push(presence_check);
[ var properties = [
'tail', 'tail_x', 'tail_y', 'tip', 'tip_x', 'tip_y', 'coords', 'tail', 'tail_x', 'tail_y', 'tip', 'tip_x', 'tip_y', 'coords',
'length', 'angle', 'segment_angle', 'segment_coords', 'points_on_line' 'length', 'angle', 'segment_angle', 'segment_coords', 'points_on_line'
].forEach(function(prop) { ];
_.each(properties, function(prop) {
if (prop in answer) { if (prop in answer) {
var check = {vector: name, check: prop, expected: answer[prop]}; var check = {vector: name, check: prop, expected: answer[prop]};
if (prop + '_tolerance' in answer) { if (prop + '_tolerance' in answer) {
......
...@@ -85,11 +85,11 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -85,11 +85,11 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
} }
} }
this.settings.points.forEach(function(point, idx) { _.each(this.settings.points, function(point, idx) {
this.renderPoint(idx); this.renderPoint(idx);
}, this); }, this);
this.settings.vectors.forEach(function(vec, idx) { _.each(this.settings.vectors, function(vec, idx) {
this.renderVector(idx); this.renderVector(idx);
}, this); }, this);
...@@ -182,7 +182,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -182,7 +182,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
var lineID = lineElement.attr("id"); var lineID = lineElement.attr("id");
var titleID = lineID + "-title"; var titleID = lineID + "-title";
var titleElement = $("<title>").attr("id", titleID).text(vec.name); var titleElement = $("<title>", {"id": titleID, "text": vec.name});
lineElement.append(titleElement); lineElement.append(titleElement);
lineElement.attr("aria-labelledby", titleID); lineElement.attr("aria-labelledby", titleID);
...@@ -656,7 +656,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) { ...@@ -656,7 +656,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
VectorDraw.prototype.getState = function() { VectorDraw.prototype.getState = function() {
var vectors = []; var vectors = [];
this.settings.vectors.forEach(function(vec) { _.each(this.settings.vectors, function(vec) {
if (vec.deleted) { if (vec.deleted) {
return; return;
} }
......
...@@ -34,11 +34,11 @@ ...@@ -34,11 +34,11 @@
<span class="reset-label" aria-hidden="true">{% trans "Reset" %}</span> <span class="reset-label" aria-hidden="true">{% trans "Reset" %}</span>
<span class="sr">{% trans "Reset board to initial state" %}</span> <span class="sr">{% trans "Reset board to initial state" %}</span>
</button> </button>
<button class="redo" title="Redo"> <button class="redo" title="{% trans 'Redo' %}">
<span class="redo-label fa fa-repeat" aria-hidden="true"></span> <span class="redo-label fa fa-repeat" aria-hidden="true"></span>
<span class="sr">{% trans "Redo last action" %}</span> <span class="sr">{% trans "Redo last action" %}</span>
</button> </button>
<button class="undo" title="Undo"> <button class="undo" title="{% trans 'Undo' %}">
<span class="undo-label fa fa-undo" aria-hidden="true"></span> <span class="undo-label fa fa-undo" aria-hidden="true"></span>
<span class="sr">{% trans "Undo last action" %}</span> <span class="sr">{% trans "Undo last action" %}</span>
</button> </button>
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
id="xb-field-edit-{{field.name}}" id="xb-field-edit-{{field.name}}"
aria-describedby="{{field.name}}-help"> aria-describedby="{{field.name}}-help">
<option value="1" {% if field.value %}selected{% endif %}> <option value="1" {% if field.value %}selected{% endif %}>
True {% if field.default %}&nbsp;&nbsp;&nbsp;&nbsp;(Default){% endif %} {% trans "True" %} {% if field.default %}&nbsp;&nbsp;&nbsp;&nbsp;({% trans "Default" %}){% endif %}
</option> </option>
<option value="0" {% if not field.value %}selected{% endif %}> <option value="0" {% if not field.value %}selected{% endif %}>
False {% if not field.default %}&nbsp;&nbsp;&nbsp;&nbsp;(Default){% endif %} {% trans "False" %} {% if not field.default %}&nbsp;&nbsp;&nbsp;&nbsp;({% trans "Default" %}){% endif %}
</option> </option>
</select> </select>
{% elif field.type == "string" %} {% elif field.type == "string" %}
...@@ -68,7 +68,10 @@ ...@@ -68,7 +68,10 @@
WYSIWYG Editor WYSIWYG Editor
<button class="info-button" title="Info"> <button class="info-button" title="Info">
<span class="info-label fa fa-question" aria-hidden="true"></span> <span class="info-label fa fa-question" aria-hidden="true"></span>
<span class="sr">{% trans "Toggle information about how to use WYSIWYG editor" %}</span> <span class="sr">
{# Translators: WYSIWYG stands for What You See Is What You Get. When using a WYSIWYG editor, the content being edited is shown in a way that closely corresponds to the finished product. #}
{% trans "Toggle information about how to use the WYSIWYG editor" %}
</span>
</button> </button>
</h2> </h2>
......
...@@ -486,27 +486,27 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -486,27 +486,27 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
# Check vectors # Check vectors
vectors = data.get('vectors') vectors = data.get('vectors')
if not isinstance(vectors, dict): if not isinstance(vectors, dict):
return False raise ValueError
for vector_data in vectors.values(): for vector_data in vectors.values():
# Validate vector # Validate vector
if not vector_data.viewkeys() == {'tail', 'tip'}: if not vector_data.viewkeys() == {'tail', 'tip'}:
return False raise ValueError
# Validate tip and tail # Validate tip and tail
tip = vector_data['tip'] tip = vector_data['tip']
tip_valid = isinstance(tip, list) and len(tip) == 2 tip_valid = isinstance(tip, list) and len(tip) == 2
tail = vector_data['tail'] tail = vector_data['tail']
tail_valid = isinstance(tail, list) and len(tail) == 2 tail_valid = isinstance(tail, list) and len(tail) == 2
if not (tip_valid and tail_valid): if not (tip_valid and tail_valid):
return False raise ValueError
# Check points # Check points
points = data.get('points') points = data.get('points')
if not isinstance(points, dict): if not isinstance(points, dict):
return False raise ValueError
for coords in points.values(): for coords in points.values():
# Validate point # Validate point
point_valid = isinstance(coords, list) and len(coords) == 2 point_valid = isinstance(coords, list) and len(coords) == 2
if not point_valid: if not point_valid:
return False raise ValueError
# If we get to this point, it means that vector and point data is valid; # If we get to this point, it means that vector and point data is valid;
# the only thing left to check is whether data contains a list of checks: # the only thing left to check is whether data contains a list of checks:
return 'checks' in data return 'checks' in data
...@@ -517,7 +517,9 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -517,7 +517,9 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
Check and persist student's answer to this vector drawing problem. Check and persist student's answer to this vector drawing problem.
""" """
# Validate data # Validate data
if not self._validate_check_answer_data(data): try:
self._validate_check_answer_data(data)
except ValueError:
raise JsonHandlerError(400, "Invalid data") raise JsonHandlerError(400, "Invalid data")
# Save answer # Save answer
self.answer = dict( self.answer = dict(
......
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