From 6d3516a754e311a454b10d4576caf44fee537dc7 Mon Sep 17 00:00:00 2001 From: kimth Date: Fri, 13 Jul 2012 13:45:38 -0400 Subject: [PATCH 1/2] CodeResponse for queued code checking --- common/lib/capa/capa/capa_problem.py | 9 ++ common/lib/capa/capa/responsetypes.py | 121 ++++++++++++++++++++- common/lib/xmodule/xmodule/capa_module.py | 10 ++ lms/djangoapps/courseware/module_render.py | 54 ++++++++- lms/urls.py | 1 + 5 files changed, 192 insertions(+), 3 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 46f6c7ad7c..344843ba10 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -179,6 +179,15 @@ class LoncapaProblem(object): return {'score': correct, 'total': self.get_max_score()} + def update_score(self, score_msg): + newcmap = CorrectMap() + for responder in self.responders.values(): + if hasattr(responder,'update_score'): # Is this the best way to implement 'update_score' for CodeResponse? + results = responder.update_score(score_msg) + newcmap.update(results) + self.correct_map = newcmap + return newcmap + def grade_answers(self, answers): ''' Grade student responses. Called by capa_module.check_problem. diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 9e8c1e97f5..b645a2faa7 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -18,6 +18,7 @@ import re import requests import traceback import abc +import time # specific library imports from calc import evaluator, UndefinedVariable @@ -693,6 +694,124 @@ class SymbolicResponse(CustomResponse): #----------------------------------------------------------------------------- +class CodeResponse(LoncapaResponse): + ''' + Grade student code using an external server + ''' + + response_tag = 'coderesponse' + allowed_inputfields = ['textline', 'textbox'] + + def setup_response(self): + xml = self.xml + self.url = xml.get('url') or "http://ec2-50-16-59-149.compute-1.amazonaws.com/xqueue/submit/" # FIXME -- hardcoded url + + answer = xml.find('answer') + if answer is not None: + answer_src = answer.get('src') + if answer_src is not None: + self.code = self.system.filesystem.open('src/'+answer_src).read() + else: + self.code = answer.text + else: # no stanza; get code from