From e55bb845b26731cb1727406e9d0fe0cdccd35d38 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Fri, 1 Mar 2013 16:05:58 -0500 Subject: [PATCH 1/4] Fix for script tags w/in json objects being oddly evaluated on html page load by doing load separately. In process, upgraded backbone which necessitated changing getByCid to get and got rid of obsolete course_settings master object. --- .../js/models/settings/course_settings.js | 42 ----------- cms/static/js/views/course_info_edit.js | 6 +- cms/templates/course_info.html | 2 +- common/static/js/vendor/backbone-min.js | 72 ++++++++++--------- 4 files changed, 42 insertions(+), 80 deletions(-) delete mode 100644 cms/static/js/models/settings/course_settings.js diff --git a/cms/static/js/models/settings/course_settings.js b/cms/static/js/models/settings/course_settings.js deleted file mode 100644 index 62b214e853..0000000000 --- a/cms/static/js/models/settings/course_settings.js +++ /dev/null @@ -1,42 +0,0 @@ -if (!CMS.Models['Settings']) CMS.Models.Settings = new Object(); -CMS.Models.Settings.CourseSettings = Backbone.Model.extend({ - // a container for the models representing the n possible tabbed states - defaults: { - courseLocation: null, - details: null, - faculty: null, - grading: null, - problems: null, - discussions: null - }, - - retrieve: function(submodel, callback) { - if (this.get(submodel)) callback(); - else { - var cachethis = this; - switch (submodel) { - case 'details': - var details = new CMS.Models.Settings.CourseDetails({location: this.get('courseLocation')}); - details.fetch( { - success : function(model) { - cachethis.set('details', model); - callback(model); - } - }); - break; - case 'grading': - var grading = new CMS.Models.Settings.CourseGradingPolicy({course_location: this.get('courseLocation')}); - grading.fetch( { - success : function(model) { - cachethis.set('grading', model); - callback(model); - } - }); - break; - - default: - break; - } - } - } -}) \ No newline at end of file diff --git a/cms/static/js/views/course_info_edit.js b/cms/static/js/views/course_info_edit.js index 277a15b57c..26fbba35a4 100644 --- a/cms/static/js/views/course_info_edit.js +++ b/cms/static/js/views/course_info_edit.js @@ -44,6 +44,8 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ self.render(); } ); + // when the client refetches the updates as a whole, re-render them + this.listenTo(this.collection, 'reset', this.render); }, render: function () { @@ -150,7 +152,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ }, closeEditor: function(self, removePost) { - var targetModel = self.collection.getByCid(self.$currentPost.attr('name')); + var targetModel = self.collection.get(self.$currentPost.attr('name')); if(removePost) { self.$currentPost.remove(); @@ -172,7 +174,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ // Dereferencing from events to screen elements eventModel: function(event) { // not sure if it should be currentTarget or delegateTarget - return this.collection.getByCid($(event.currentTarget).attr("name")); + return this.collection.get($(event.currentTarget).attr("name")); }, modelDom: function(event) { diff --git a/cms/templates/course_info.html b/cms/templates/course_info.html index a68a0da76a..55dcaaa068 100644 --- a/cms/templates/course_info.html +++ b/cms/templates/course_info.html @@ -20,8 +20,8 @@ From 020e1e94fbf7b6977b8d34c872f9a09a635910ae Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Mon, 4 Mar 2013 15:38:47 -0500 Subject: [PATCH 4/4] Move side effecting of definition for grader to the course_module and don't make caller responsible. --- cms/djangoapps/models/settings/course_grading.py | 2 -- common/lib/xmodule/xmodule/course_module.py | 13 ++++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/cms/djangoapps/models/settings/course_grading.py b/cms/djangoapps/models/settings/course_grading.py index f1f68b5f5b..3d0b8f78af 100644 --- a/cms/djangoapps/models/settings/course_grading.py +++ b/cms/djangoapps/models/settings/course_grading.py @@ -118,8 +118,6 @@ class CourseGradingModel(object): descriptor.raw_grader[index] = grader else: descriptor.raw_grader.append(grader) - # make definition notice the update - descriptor.raw_grader = descriptor.raw_grader get_modulestore(course_location).update_item(course_location, descriptor.definition['data']) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 2ed780fcae..86ae673ae8 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -127,6 +127,7 @@ class CourseDescriptor(SequenceDescriptor): # NOTE (THK): This is a last-minute addition for Fall 2012 launch to dynamically # disable the syllabus content for courses that do not provide a syllabus self.syllabus_present = self.system.resources_fs.exists(path('syllabus')) + self._grading_policy = {} self.set_grading_policy(self.definition['data'].get('grading_policy', None)) self.test_center_exams = [] @@ -196,11 +197,9 @@ class CourseDescriptor(SequenceDescriptor): grading_policy.update(course_policy) # Here is where we should parse any configurations, so that we can fail early - grading_policy['RAW_GRADER'] = grading_policy['GRADER'] # used for cms access - grading_policy['GRADER'] = grader_from_conf(grading_policy['GRADER']) - self._grading_policy = grading_policy - - + # Use setters so that side effecting to .definitions works + self.raw_grader = grading_policy['GRADER'] # used for cms access + self.grade_cutoffs = grading_policy['GRADE_CUTOFFS'] @classmethod def read_grading_policy(cls, paths, system): @@ -317,10 +316,6 @@ class CourseDescriptor(SequenceDescriptor): if isinstance(value, time.struct_time): self.metadata['enrollment_end'] = stringify_time(value) - @property - def grader(self): - return self._grading_policy['GRADER'] - @property def raw_grader(self): return self._grading_policy['RAW_GRADER']