From ce995e06e3509a1340061c51dfa08a65c69eef66 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 14 Aug 2017 12:10:42 +0530 Subject: Front-end modification for improved code server Added JQuery to handle request. Sends ajax request and gets json as response. json contains token i.e uid which is answer id. Using uid, an ajax request is sent after every 2 secs till the server gives the desire result. If the code result has error then html is written on the document. If the result has correct answer then next question is displayed. *includes function for string will not work for older browers. Will substitute with a different function in next commit. --- yaksh/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 87e6260..9b3cabe 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -24,7 +24,7 @@ import zipfile import tempfile from textwrap import dedent from .file_utils import extract_files, delete_files -from yaksh.xmlrpc_clients import code_server +from yaksh.code_server import submit, SERVER_POOL_PORT from django.conf import settings @@ -1266,7 +1266,7 @@ class AnswerPaper(models.Model): if question.type == 'code': return self.answers.filter(question=question).order_by('-id') - def validate_answer(self, user_answer, question, json_data=None): + def validate_answer(self, user_answer, question, json_data=None, uid=None): """ Checks whether the answer submitted by the user is right or wrong. If right then returns correct = True, success and @@ -1327,10 +1327,9 @@ class AnswerPaper(models.Model): elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() - json_result = code_server.run_code( - question.language, json_data, user_dir - ) - result = json.loads(json_result) + url = 'http://localhost:%s' % SERVER_POOL_PORT + submit(url, uid, json_data, user_dir) + result = {'uid': uid, 'state': 'running'} return result def regrade(self, question_id): -- cgit