Commit 645115fb by Tim Krones

Address upstream review comments.

parent 0d4a06ac
......@@ -288,10 +288,10 @@ class TestVectorDraw(StudioEditableBaseTest):
expected_line_position = position.items()
for line in line_elements:
line_position = {
"x1": int(float(line.get_attribute("x1"))),
"y1": int(float(line.get_attribute("y1"))),
"x2": int(float(line.get_attribute("x2"))),
"y2": int(float(line.get_attribute("y2"))),
"x1": int(line.get_attribute("x1").split(".", 1)[0]),
"y1": int(line.get_attribute("y1").split(".", 1)[0]),
"x2": int(line.get_attribute("x2").split(".", 1)[0]),
"y2": int(line.get_attribute("y2").split(".", 1)[0]),
}.items()
if line_position == expected_line_position:
return line
......@@ -300,8 +300,8 @@ class TestVectorDraw(StudioEditableBaseTest):
expected_position = position.items()
for point in point_elements:
point_position = {
"cx": int(round(float(point.get_attribute("cx")))),
"cy": int(round(float(point.get_attribute("cy")))),
"cx": int(point.get_attribute("cx").split(".", 1)[0]),
"cy": int(point.get_attribute("cy").split(".", 1)[0]),
}.items()
if point_position == expected_position:
return point
......@@ -377,9 +377,9 @@ class TestVectorDraw(StudioEditableBaseTest):
self.assertTrue(status.is_displayed())
correctness = status.find_element_by_css_selector(".correctness")
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:
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")
self.assertEquals(status_message.text, expected_message)
......@@ -915,7 +915,7 @@ class TestVectorDraw(StudioEditableBaseTest):
self.change_property("tail", "3, 3")
# Check new position: Tail updated, tip updated
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}
self.assert_vectors(board, vectors)
......
......@@ -99,11 +99,11 @@ function VectorDrawXBlock(runtime, element, init_args) {
vectorProperties.attr("id", id + "-vector-properties");
// Draw vectors and points
this.settings.points.forEach(function(point, idx) {
_.each(this.settings.points, function(point, idx) {
renderAndSetMenuOptions(point, idx, 'point', this);
}, this);
this.settings.vectors.forEach(function(vec, idx) {
_.each(this.settings.vectors, function(vec, idx) {
renderAndSetMenuOptions(vec, idx, 'vector', this);
}, this);
......@@ -210,7 +210,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
var lineID = lineElement.attr("id");
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.attr("aria-labelledby", titleID);
......@@ -245,7 +245,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
selector = selector.split('-');
return {
type: selector[0],
idx: parseInt(selector[1])
idx: parseInt(selector[1], 10)
};
}
return {};
......@@ -513,13 +513,13 @@ function VectorDrawXBlock(runtime, element, init_args) {
VectorDraw.prototype.getState = function() {
var vectors = {}, points = {};
this.settings.vectors.forEach(function(vec) {
_.each(this.settings.vectors, function(vec) {
var coords = this.getVectorCoords(vec.name);
if (coords) {
vectors[vec.name] = coords;
}
}, this);
this.settings.points.forEach(function(point) {
_.each(this.settings.points, function(point) {
var obj = this.board.elementsByName[point.name];
if (obj) {
points[point.name] = [obj.X(), obj.Y()];
......@@ -529,7 +529,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
};
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];
if (vec_state) {
this.renderVector(idx, [vec_state.tail, vec_state.tip]);
......@@ -537,7 +537,7 @@ function VectorDrawXBlock(runtime, element, init_args) {
this.removeVector(idx);
}
}, this);
this.settings.points.forEach(function(point, idx) {
_.each(this.settings.points, function(point, idx) {
var point_state = state.points[point.name];
if (point_state) {
this.renderPoint(idx, point_state);
......@@ -567,10 +567,11 @@ function VectorDrawXBlock(runtime, element, init_args) {
}
checks.push(presence_check);
[
var properties = [
'tail', 'tail_x', 'tail_y', 'tip', 'tip_x', 'tip_y', 'coords',
'length', 'angle', 'segment_angle', 'segment_coords', 'points_on_line'
].forEach(function(prop) {
];
_.each(properties, function(prop) {
if (prop in answer) {
var check = {vector: name, check: prop, expected: answer[prop]};
if (prop + '_tolerance' in answer) {
......
......@@ -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);
this.settings.vectors.forEach(function(vec, idx) {
_.each(this.settings.vectors, function(vec, idx) {
this.renderVector(idx);
}, this);
......@@ -182,7 +182,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
var lineID = lineElement.attr("id");
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.attr("aria-labelledby", titleID);
......@@ -656,7 +656,7 @@ function VectorDrawXBlockEdit(runtime, element, init_args) {
VectorDraw.prototype.getState = function() {
var vectors = [];
this.settings.vectors.forEach(function(vec) {
_.each(this.settings.vectors, function(vec) {
if (vec.deleted) {
return;
}
......
......@@ -34,11 +34,11 @@
<span class="reset-label" aria-hidden="true">{% trans "Reset" %}</span>
<span class="sr">{% trans "Reset board to initial state" %}</span>
</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="sr">{% trans "Redo last action" %}</span>
</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="sr">{% trans "Undo last action" %}</span>
</button>
......
......@@ -15,10 +15,10 @@
id="xb-field-edit-{{field.name}}"
aria-describedby="{{field.name}}-help">
<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 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>
</select>
{% elif field.type == "string" %}
......@@ -68,7 +68,10 @@
WYSIWYG Editor
<button class="info-button" title="Info">
<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>
</h2>
......
......@@ -486,27 +486,27 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
# Check vectors
vectors = data.get('vectors')
if not isinstance(vectors, dict):
return False
raise ValueError
for vector_data in vectors.values():
# Validate vector
if not vector_data.viewkeys() == {'tail', 'tip'}:
return False
raise ValueError
# Validate tip and tail
tip = vector_data['tip']
tip_valid = isinstance(tip, list) and len(tip) == 2
tail = vector_data['tail']
tail_valid = isinstance(tail, list) and len(tail) == 2
if not (tip_valid and tail_valid):
return False
raise ValueError
# Check points
points = data.get('points')
if not isinstance(points, dict):
return False
raise ValueError
for coords in points.values():
# Validate point
point_valid = isinstance(coords, list) and len(coords) == 2
if not point_valid:
return False
raise ValueError
# 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:
return 'checks' in data
......@@ -517,7 +517,9 @@ class VectorDrawXBlock(StudioEditableXBlockMixin, XBlock):
Check and persist student's answer to this vector drawing problem.
"""
# Validate data
if not self._validate_check_answer_data(data):
try:
self._validate_check_answer_data(data)
except ValueError:
raise JsonHandlerError(400, "Invalid data")
# Save answer
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