From 0fc16dffee447a8fa440127b33178c3723adf2e1 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Fri, 14 Dec 2012 12:29:57 -0500 Subject: [PATCH] Gradable impl'd for overview page --- .../models/settings/course_grading.py | 12 +++---- cms/static/js/views/grader-select-view.js | 35 +++++++++++-------- cms/templates/overview.html | 9 +++-- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/cms/djangoapps/models/settings/course_grading.py b/cms/djangoapps/models/settings/course_grading.py index 5a998bb044..358e0a851b 100644 --- a/cms/djangoapps/models/settings/course_grading.py +++ b/cms/djangoapps/models/settings/course_grading.py @@ -199,7 +199,7 @@ class CourseGradingModel: course_location = Location(course_location) descriptor = get_modulestore(course_location).get_item(course_location) - del descriptor.metadata['graceperiod'] + if 'graceperiod' in descriptor.metadata: del descriptor.metadata['graceperiod'] get_modulestore(course_location).update_metadata(course_location, descriptor.metadata) @staticmethod @@ -209,7 +209,7 @@ class CourseGradingModel: descriptor = get_modulestore(location).get_item(location) return { - "grader-type" : descriptor.metadata.get('format', "Not Graded"), + "graderType" : descriptor.metadata.get('format', u"Not Graded"), "location" : location, "id" : 99 # just an arbitrary value to } @@ -220,12 +220,12 @@ class CourseGradingModel: location = Location(location) descriptor = get_modulestore(location).get_item(location) - if 'grader-type' in jsondict: - descriptor.metadata['format'] = jsondict.get('grader-type') + if 'graderType' in jsondict and jsondict['graderType'] != u"Not Graded": + descriptor.metadata['format'] = jsondict.get('graderType') descriptor.metadata['graded'] = True else: - del descriptor.metadata['format'] - descriptor.metadata['graded'] = False + if 'format' in descriptor.metadata: del descriptor.metadata['format'] + if 'graded' in descriptor.metadata: del descriptor.metadata['graded'] get_modulestore(location).update_metadata(location, descriptor.metadata) diff --git a/cms/static/js/views/grader-select-view.js b/cms/static/js/views/grader-select-view.js index 1107273cff..a6528f6205 100644 --- a/cms/static/js/views/grader-select-view.js +++ b/cms/static/js/views/grader-select-view.js @@ -1,19 +1,19 @@ CMS.Models.AssignmentGrade = Backbone.Model.extend({ idAttribute : "cid", // not sure if this is kosher defaults : { - grader-type : null, // the type label (string). May be "Not Graded" which implies None. I'd like to use id but that's ephemeral + graderType : null, // the type label (string). May be "Not Graded" which implies None. I'd like to use id but that's ephemeral location : null // A location object }, initialize : function(attrs) { - if (attrs['assignment-url']) { - this.set('location') = new CMS.Models.Location(attrs['assignment-url'], {parse: true}); + if (attrs['assignmentUrl']) { + this.set('location', new CMS.Models.Location(attrs['assignmentUrl'], {parse: true})); } }, parse : function(attrs) { - if (attrs['location']) { + if (attrs && attrs['location']) { attrs.location = new CMS.Models.Location(attrs['location'], {parse: true}); } - } + }, urlRoot : function() { if (this.has('location')) { var location = this.get('location'); @@ -31,26 +31,29 @@ CMS.Views.OverviewAssignmentGrader = Backbone.View.extend({ "click .menu" : "selectGradeType" }, initialize : function() { - // call template w/ {assignment-type : formatname, graders : CourseGraderCollection instance } + // call template w/ {assignmentType : formatname, graders : CourseGraderCollection instance } this.template = _.template( - '

<%= assignment-type %>

' + + // TODO move to a template file + '

<%= assignmentType %>

' + '' + '' + '' + ''); this.assignmentGrade = new CMS.Models.AssignmentGrade({ - assignment-url : this.$el.closest('section.branch').data('id'), - grader-type : this.$el.data('initial-status')}); + assignmentUrl : this.$el.closest('.branch').data('id'), + graderType : this.$el.data('initial-status')}); + // TODO throw exception if graders is null + this.graders = this.options['graders']; this.render(); }, render : function() { - this.$el.html(this.template({ assignment-type : this.assignmentGrade.get('grader-type'), graders : this.graders })); - if (this.assignmentGrade.has('grader-type') && assignmentGrade.get('grader-type') != "Not Graded") { + this.$el.html(this.template({ assignmentType : this.assignmentGrade.get('graderType'), graders : this.graders })); + if (this.assignmentGrade.has('graderType') && this.assignmentGrade.get('graderType') != "Not Graded") { this.$el.addClass('is-set'); } else { @@ -63,10 +66,12 @@ CMS.Views.OverviewAssignmentGrader = Backbone.View.extend({ }, selectGradeType : function(e) { e.preventDefault(); + + this.$el.toggleClass('is-active'); // TODO I'm not happy with this string fetch via the html for what should be an id. I'd rather use the id attr // of the CourseGradingPolicy model or null for Not Graded (NOTE, change template's if check for is-selected accordingly) - this.assignmentGrade.save('grader-type', $(e.target).html()); + this.assignmentGrade.save('graderType', $(e.target).text()); this.render(); } diff --git a/cms/templates/overview.html b/cms/templates/overview.html index 132dbee5aa..83af8ac323 100644 --- a/cms/templates/overview.html +++ b/cms/templates/overview.html @@ -16,15 +16,18 @@ - + +