Commit 5ea5a7c0 by Don Mitchell

It works!!!

parent c43aa62f
...@@ -1006,6 +1006,7 @@ def course_grader_updates(request, org, course, name, grader_index=None): ...@@ -1006,6 +1006,7 @@ def course_grader_updates(request, org, course, name, grader_index=None):
elif real_method == "DELETE": elif real_method == "DELETE":
# ??? Shoudl this return anything? Perhaps success fail? # ??? Shoudl this return anything? Perhaps success fail?
CourseGradingModel.delete_grader(Location(['i4x', org, course, 'course',name]), grader_index) CourseGradingModel.delete_grader(Location(['i4x', org, course, 'course',name]), grader_index)
return HttpResponse()
elif request.method == 'POST': # post or put, doesn't matter. elif request.method == 'POST': # post or put, doesn't matter.
return HttpResponse(json.dumps(CourseGradingModel.update_grader_from_json(Location(['i4x', org, course, 'course',name]), request.POST)), return HttpResponse(json.dumps(CourseGradingModel.update_grader_from_json(Location(['i4x', org, course, 'course',name]), request.POST)),
mimetype="application/json") mimetype="application/json")
......
...@@ -42,7 +42,7 @@ class CourseGradingModel: ...@@ -42,7 +42,7 @@ class CourseGradingModel:
# # ??? it would be good if these had the course_location in them so that they stand alone sufficiently # # ??? it would be good if these had the course_location in them so that they stand alone sufficiently
# # but that would require not using CourseDescriptor's field directly. Opinions? # # but that would require not using CourseDescriptor's field directly. Opinions?
# FIXME how do I tell it to ignore index? Is there another iteration mech I should use? index = int(index)
if len(descriptor.raw_grader) > index: if len(descriptor.raw_grader) > index:
return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index]) return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index])
...@@ -113,7 +113,7 @@ class CourseGradingModel: ...@@ -113,7 +113,7 @@ class CourseGradingModel:
# # but that would require not using CourseDescriptor's field directly. Opinions? # # but that would require not using CourseDescriptor's field directly. Opinions?
# parse removes the id; so, grab it before parse # parse removes the id; so, grab it before parse
index = grader.get('id', None) index = int(grader.get('id', len(descriptor.raw_grader)))
grader = CourseGradingModel.parse_grader(grader) grader = CourseGradingModel.parse_grader(grader)
if index < len(descriptor.raw_grader): if index < len(descriptor.raw_grader):
...@@ -172,8 +172,11 @@ class CourseGradingModel: ...@@ -172,8 +172,11 @@ class CourseGradingModel:
course_location = Location(course_location) course_location = Location(course_location)
descriptor = get_modulestore(course_location).get_item(course_location) descriptor = get_modulestore(course_location).get_item(course_location)
index = int(index)
if index < len(descriptor.raw_grader): if index < len(descriptor.raw_grader):
del descriptor.raw_grader[index] del descriptor.raw_grader[index]
# force propagation to defintion
descriptor.raw_grader = descriptor.raw_grader
get_modulestore(course_location).update_item(course_location, descriptor.definition['data']) get_modulestore(course_location).update_item(course_location, descriptor.definition['data'])
# NOTE cannot delete cutoffs. May be useful to reset # NOTE cannot delete cutoffs. May be useful to reset
......
...@@ -37,7 +37,7 @@ CMS.Models.Settings.CourseGradingPolicy = Backbone.Model.extend({ ...@@ -37,7 +37,7 @@ CMS.Models.Settings.CourseGradingPolicy = Backbone.Model.extend({
CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({
defaults: { defaults: {
"type" : "", // must be unique w/in collection (ie. w/in course) "type" : "", // must be unique w/in collection (ie. w/in course)
"min_count" : 0, "min_count" : 1,
"drop_count" : 0, "drop_count" : 0,
"short_label" : "", // what to use in place of type if space is an issue "short_label" : "", // what to use in place of type if space is an issue
"weight" : 0 // int 0..100 "weight" : 0 // int 0..100
...@@ -73,7 +73,7 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ ...@@ -73,7 +73,7 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({
} }
} }
if (attrs['weight']) { if (attrs['weight']) {
if (!isFinite(attrs.weight) || !parseInt(attrs.weight)) { if (!isFinite(attrs.weight) || /\D+/.test(attrs.weight)) {
errors.weight = "Please enter an integer between 0 and 100."; errors.weight = "Please enter an integer between 0 and 100.";
} }
else { else {
...@@ -87,13 +87,13 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ ...@@ -87,13 +87,13 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({
} }
}} }}
if (attrs['min_count']) { if (attrs['min_count']) {
if (!isFinite(attrs.min_count) || !parseInt(attrs.min_count)) { if (!isFinite(attrs.min_count) || /\D+/.test(attrs.min_count)) {
errors.min_count = "Please enter an integer."; errors.min_count = "Please enter an integer.";
} }
else attrs.min_count = parseInt(attrs.min_count); else attrs.min_count = parseInt(attrs.min_count);
} }
if (attrs['drop_count']) { if (attrs['drop_count']) {
if (!isFinite(attrs.drop_count) || !parseInt(attrs.drop_count)) { if (!isFinite(attrs.drop_count) || /\D+/.test(attrs.drop_count)) {
errors.drop_count = "Please enter an integer."; errors.drop_count = "Please enter an integer.";
} }
else attrs.drop_count = parseInt(attrs.drop_count); else attrs.drop_count = parseInt(attrs.drop_count);
...@@ -109,7 +109,7 @@ CMS.Models.Settings.CourseGraderCollection = Backbone.Collection.extend({ ...@@ -109,7 +109,7 @@ CMS.Models.Settings.CourseGraderCollection = Backbone.Collection.extend({
model : CMS.Models.Settings.CourseGrader, model : CMS.Models.Settings.CourseGrader,
course_location : null, // must be set to a Location object course_location : null, // must be set to a Location object
url : function() { url : function() {
return '/' + this.course_location.get('org') + "/" + this.course_location.get('course') + '/grades/' + this.course_location.get('name'); return '/' + this.course_location.get('org') + "/" + this.course_location.get('course') + '/grades/' + this.course_location.get('name') + '/';
}, },
sumWeights : function() { sumWeights : function() {
return this.reduce(function(subtotal, grader) { return subtotal + grader.get('weight'); }, 0); return this.reduce(function(subtotal, grader) { return subtotal + grader.get('weight'); }, 0);
......
...@@ -265,7 +265,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -265,7 +265,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
"blur span[contenteditable=true]" : "updateDesignation", "blur span[contenteditable=true]" : "updateDesignation",
"click .settings-extra header" : "showSettingsExtras", "click .settings-extra header" : "showSettingsExtras",
"click .new-grade-button" : "addNewGrade", "click .new-grade-button" : "addNewGrade",
"click .remove-button" : "removeGrade" "click .remove-button" : "removeGrade",
"click .add-grading-data" : "addAssignmentType"
}, },
initialize : function() { initialize : function() {
// load template for grading view // load template for grading view
...@@ -299,6 +300,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -299,6 +300,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
} }
); );
this.model.on('error', this.handleValidationError, this); this.model.on('error', this.handleValidationError, this);
this.model.get('graders').on('remove', this.render, this);
this.model.get('graders').on('add', this.render, this);
this.selectorToField = _.invert(this.fieldToSelectorMap); this.selectorToField = _.invert(this.fieldToSelectorMap);
}, },
...@@ -323,6 +326,9 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -323,6 +326,9 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
return this; return this;
}, },
addAssignmentType : function() {
this.model.get('graders').push({});
},
fieldToSelectorMap : { fieldToSelectorMap : {
'grace_period' : 'course-grading-graceperiod' 'grace_period' : 'course-grading-graceperiod'
}, },
...@@ -545,7 +551,8 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ ...@@ -545,7 +551,8 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
// Model class is CMS.Models.Settings.CourseGrader // Model class is CMS.Models.Settings.CourseGrader
events : { events : {
"blur input" : "updateModel", "blur input" : "updateModel",
"blur textarea" : "updateModel" "blur textarea" : "updateModel",
"click .remove-grading-data" : "deleteModel"
}, },
initialize : function() { initialize : function() {
this.model.on('error', this.handleValidationError, this); this.model.on('error', this.handleValidationError, this);
...@@ -577,6 +584,9 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ ...@@ -577,6 +584,9 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
break; break;
} }
},
deleteModel : function() {
this.model.destroy();
} }
}); });
\ No newline at end of file
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