From 0622dc995d9d9fdfe257dc1911a37187875d9ca5 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Tue, 29 Jan 2013 22:42:08 -0500 Subject: [PATCH] Javascript to handle file uploads --- .../lib/xmodule/xmodule/combined_open_ended_module.py | 6 +++--- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 10 +++++----- .../xmodule/js/src/combinedopenended/display.coffee | 7 +++++-- common/lib/xmodule/xmodule/self_assessment_module.py | 1 + 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/combined_open_ended_module.py b/common/lib/xmodule/xmodule/combined_open_ended_module.py index d74657d923..1ed57fa844 100644 --- a/common/lib/xmodule/xmodule/combined_open_ended_module.py +++ b/common/lib/xmodule/xmodule/combined_open_ended_module.py @@ -39,7 +39,7 @@ MAX_SCORE = 1 MAX_SCORE_ALLOWED = 3 IS_SCORED=False -ACCEPT_FILE_UPLOAD = False +ACCEPT_FILE_UPLOAD = True class CombinedOpenEndedModule(XModule): """ @@ -141,8 +141,8 @@ class CombinedOpenEndedModule(XModule): #Allow reset is true if student has failed the criteria to move to the next child task self.allow_reset = instance_state.get('ready_to_reset', False) self.max_attempts = int(self.metadata.get('attempts', MAX_ATTEMPTS)) - self.is_scored = (self.metadata.get('is_graded', IS_SCORED)=="True") - self.accept_file_upload = (self.metadata.get('accept_file_upload', ACCEPT_FILE_UPLOAD)=="True") + self.is_scored = (self.metadata.get('is_graded', IS_SCORED) in [True, "True"]) + self.accept_file_upload = (self.metadata.get('accept_file_upload', ACCEPT_FILE_UPLOAD) in [True, "True"]) log.debug(self.metadata.get('is_graded', IS_SCORED)) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 1c0ace9e59..5890686c0e 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -140,15 +140,15 @@ class @Problem allowed_files = $(element).data("allowed_files") for file in element.files if allowed_files.length != 0 and file.name not in allowed_files - unallowed_file_submitted = true - errors.push "You submitted #{file.name}; only #{allowed_files} are allowed." + unallowed_file_submitted = true + errors.push "You submitted #{file.name}; only #{allowed_files} are allowed." if file.name in required_files - required_files.splice(required_files.indexOf(file.name), 1) + required_files.splice(required_files.indexOf(file.name), 1) if file.size > max_filesize file_too_large = true errors.push 'Your file "' + file.name '" is too large (max size: ' + max_filesize/(1000*1000) + ' MB)' fd.append(element.id, file) - if element.files.length == 0 + if element.files.length == 0 file_not_selected = true fd.append(element.id, '') # In case we want to allow submissions with no file if required_files.length != 0 @@ -157,7 +157,7 @@ class @Problem else fd.append(element.id, element.value) - + if file_not_selected errors.push 'You did not select any files to submit' diff --git a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee index 9d8ee96b91..5c307f664e 100644 --- a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee @@ -179,7 +179,11 @@ class @CombinedOpenEnded save_answer: (event) => event.preventDefault() if @child_state == 'initial' - data = {'student_answer' : @answer_area.val()} + file_data = "" + if @can_upload_files == true + files = $('.file-upload-box')[0].files[0] + file_data = files + data = {'student_answer' : @answer_area.val(), 'file_data' : file_data} $.postWithPrefix "#{@ajax_url}/save_answer", data, (response) => if response.success @rubric_wrapper.html(response.rubric_html) @@ -307,7 +311,6 @@ class @CombinedOpenEnded setup_file_upload: => if window.File and window.FileReader and window.FileList and window.Blob - alert('File API supported.') if @accept_file_upload == "True" @can_upload_files = true @file_upload_area.html('') diff --git a/common/lib/xmodule/xmodule/self_assessment_module.py b/common/lib/xmodule/xmodule/self_assessment_module.py index efc25f841b..96fc4a3c86 100644 --- a/common/lib/xmodule/xmodule/self_assessment_module.py +++ b/common/lib/xmodule/xmodule/self_assessment_module.py @@ -107,6 +107,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild): if dispatch not in handlers: return 'Error' + log.debug(get) before = self.get_progress() d = handlers[dispatch](get, system) after = self.get_progress()