From 5ea5a7c0a7313bd855a2b59b219791edbb2107a5 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Mon, 10 Dec 2012 18:55:35 -0500 Subject: [PATCH] It works!!! --- cms/djangoapps/contentstore/views.py | 1 + cms/djangoapps/models/settings/course_grading.py | 9 ++++++--- .../js/models/settings/course_grading_policy.js | 10 +++++----- cms/static/js/views/settings/main_settings_view.js | 14 ++++++++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 220697bcab..df0b36c920 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -1006,6 +1006,7 @@ def course_grader_updates(request, org, course, name, grader_index=None): elif real_method == "DELETE": # ??? Shoudl this return anything? Perhaps success fail? CourseGradingModel.delete_grader(Location(['i4x', org, course, 'course',name]), grader_index) + return HttpResponse() 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)), mimetype="application/json") diff --git a/cms/djangoapps/models/settings/course_grading.py b/cms/djangoapps/models/settings/course_grading.py index b2337183a8..e111a19a88 100644 --- a/cms/djangoapps/models/settings/course_grading.py +++ b/cms/djangoapps/models/settings/course_grading.py @@ -41,8 +41,8 @@ class CourseGradingModel: descriptor = get_modulestore(course_location).get_item(course_location) # # ??? 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? - - # 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: return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index]) @@ -113,7 +113,7 @@ class CourseGradingModel: # # but that would require not using CourseDescriptor's field directly. Opinions? # 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) if index < len(descriptor.raw_grader): @@ -172,8 +172,11 @@ class CourseGradingModel: course_location = Location(course_location) descriptor = get_modulestore(course_location).get_item(course_location) + index = int(index) if index < len(descriptor.raw_grader): 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']) # NOTE cannot delete cutoffs. May be useful to reset diff --git a/cms/static/js/models/settings/course_grading_policy.js b/cms/static/js/models/settings/course_grading_policy.js index d7e62e56d1..c2f88d0789 100644 --- a/cms/static/js/models/settings/course_grading_policy.js +++ b/cms/static/js/models/settings/course_grading_policy.js @@ -37,7 +37,7 @@ CMS.Models.Settings.CourseGradingPolicy = Backbone.Model.extend({ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ defaults: { "type" : "", // must be unique w/in collection (ie. w/in course) - "min_count" : 0, + "min_count" : 1, "drop_count" : 0, "short_label" : "", // what to use in place of type if space is an issue "weight" : 0 // int 0..100 @@ -73,7 +73,7 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ } } 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."; } else { @@ -87,13 +87,13 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ } }} 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."; } else attrs.min_count = parseInt(attrs.min_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."; } else attrs.drop_count = parseInt(attrs.drop_count); @@ -109,7 +109,7 @@ CMS.Models.Settings.CourseGraderCollection = Backbone.Collection.extend({ model : CMS.Models.Settings.CourseGrader, course_location : null, // must be set to a Location object 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() { return this.reduce(function(subtotal, grader) { return subtotal + grader.get('weight'); }, 0); diff --git a/cms/static/js/views/settings/main_settings_view.js b/cms/static/js/views/settings/main_settings_view.js index 40b43b3783..51d2e69a58 100644 --- a/cms/static/js/views/settings/main_settings_view.js +++ b/cms/static/js/views/settings/main_settings_view.js @@ -265,7 +265,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ "blur span[contenteditable=true]" : "updateDesignation", "click .settings-extra header" : "showSettingsExtras", "click .new-grade-button" : "addNewGrade", - "click .remove-button" : "removeGrade" + "click .remove-button" : "removeGrade", + "click .add-grading-data" : "addAssignmentType" }, initialize : function() { // load template for grading view @@ -299,6 +300,8 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ } ); 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); }, @@ -323,6 +326,9 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ return this; }, + addAssignmentType : function() { + this.model.get('graders').push({}); + }, fieldToSelectorMap : { 'grace_period' : 'course-grading-graceperiod' }, @@ -545,7 +551,8 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ // Model class is CMS.Models.Settings.CourseGrader events : { "blur input" : "updateModel", - "blur textarea" : "updateModel" + "blur textarea" : "updateModel", + "click .remove-grading-data" : "deleteModel" }, initialize : function() { this.model.on('error', this.handleValidationError, this); @@ -577,6 +584,9 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ break; } + }, + deleteModel : function() { + this.model.destroy(); } }); \ No newline at end of file