Commit f66e07ac by Will Daly

Checkpoint -- option point validation

parent 8d668c5f
......@@ -227,8 +227,8 @@ describe("OpenAssessment.EditRubricView", function() {
// Valid option point values
testValidateOptionPoints("0", true);
testValidateOptionPoints("1", true);
testValidateOptionPoints("2", false);
testValidateOptionPoints("998", false);
testValidateOptionPoints("999", false);
testValidateOptionPoints("2", true);
testValidateOptionPoints("998", true);
testValidateOptionPoints("999", true);
});
});
......@@ -38,6 +38,7 @@ Returns:
OpenAssessment.RubricOption = function(element, notifier) {
this.element = element;
this.notifier = notifier;
this.MAX_POINTS = 1000;
$(this.element).focusout($.proxy(this.updateHandler, this));
};
......@@ -164,6 +165,37 @@ OpenAssessment.RubricOption.prototype = {
"points": optionPoints
}
);
},
/**
TODO
**/
validate: function() {
var pointString = $(".openassessment_criterion_option_points", this.element).val();
var matches = pointString.trim().match(/^\d{1,3}$/g);
var isValid = (matches !== null);
if (!isValid) {
$(".openassessment_criterion_option_points", this.element)
.addClass("openassessment_highlighted_field");
}
return isValid;
},
/**
TODO
**/
validationErrors: function() {
var sel = $(".openassessment_criterion_option_points", this.element);
var hasError = sel.hasClass("openassessment_highlighted_field");
return hasError ? ["Option points are invalid"] : [];
},
/**
TODO
**/
clearValidationErrors: function() {
$(".openassessment_criterion_option_points", this.element)
.removeClass("openassessment_highlighted_field");
}
};
......@@ -301,6 +333,37 @@ OpenAssessment.RubricCriterion.prototype = {
"criterionUpdated",
{'criterionName': criterionName, 'criterionLabel': criterionLabel}
);
},
/**
TODO
**/
validate: function() {
var isValid = true;
$.each(this.optionContainer.getAllItems(), function() {
isValid = (isValid && this.validate());
});
return isValid;
},
/**
TODO
**/
validationErrors: function() {
var errors = [];
$.each(this.optionContainer.getAllItems(), function() {
errors = errors.concat(this.validationErrors());
});
return errors;
},
/**
TODO
**/
clearValidationErrors: function() {
$.each(this.optionContainer.getAllItems(), function() {
this.clearValidationErrors();
});
}
};
......@@ -343,5 +406,9 @@ OpenAssessment.TrainingExample.prototype = {
addHandler: function() {},
removeHandler: function() {},
updateHandler: function() {}
updateHandler: function() {},
validate: function() { return true; },
validationErrors: function() { return []; },
clearValidationErrors: function() {}
};
\ No newline at end of file
......@@ -155,7 +155,7 @@ OpenAssessment.DatetimeControl.prototype = {
var dateHasError = $(this.datePicker, this.element).hasClass("openassessment_highlighted_field");
var timeHasError = $(this.timePicker, this.element).hasClass("openassessment_highlighted_field");
if(dateHasError) { errors.push("Date is invalid"); }
if (dateHasError) { errors.push("Date is invalid"); }
if (timeHasError) { errors.push("Time is invalid"); }
return errors;
......
......@@ -195,19 +195,34 @@ OpenAssessment.EditRubricView.prototype = {
TODO
**/
validate: function() {
return true;
var isValid = true;
$.each(this.getAllCriteria(), function() {
isValid = (isValid && this.validate());
});
return isValid;
},
/**
TODO
**/
validationErrors: function() {
return [];
var errors = [];
$.each(this.getAllCriteria(), function() {
errors = errors.concat(this.validationErrors());
});
return errors;
},
/**
TODO
**/
clearValidationErrors: function() {
$.each(this.getAllCriteria(), function() {
this.clearValidationErrors();
});
}
};
......@@ -25,6 +25,9 @@ templates.json file's directory.
import sys
import os.path
import json
import re
import dateutil.parser
import pytz
# This is a bit of a hack to ensure that the root repo directory
# is in the Python path, so Django can find the settings module.
......@@ -36,6 +39,29 @@ from django.template.loader import get_template
USAGE = u"{prog} TEMPLATE_DESC"
ISO_DATE_REGEX = re.compile("^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$")
def parse_dates(context):
"""
TODO
"""
if isinstance(context, dict):
return {
key: parse_dates(value)
for key, value in context.iteritems()
}
elif isinstance(context, list):
return [
parse_dates(item)
for item in context
]
elif isinstance(context, basestring):
if ISO_DATE_REGEX.match(context) is not None:
return dateutil.parser.parse(context).replace(tzinfo=pytz.utc)
return context
def render_templates(root_dir, template_json):
"""
Create rendered templates.
......@@ -51,7 +77,8 @@ def render_templates(root_dir, template_json):
"""
for template_dict in template_json:
template = get_template(template_dict['template'])
rendered = template.render(Context(template_dict['context']))
context = parse_dates(template_dict['context'])
rendered = template.render(Context(context))
output_path = os.path.join(root_dir, template_dict['output'])
try:
......
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