summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorprathamesh2017-08-14 12:10:42 +0530
committerprathamesh2017-08-14 12:10:42 +0530
commitce995e06e3509a1340061c51dfa08a65c69eef66 (patch)
treed270ccf9792bd2dbbc833e2f08aee4b407356cb9 /yaksh/models.py
parent1a6006b457a68e6db51315a83a97ec0d9eb631d4 (diff)
downloadonline_test-ce995e06e3509a1340061c51dfa08a65c69eef66.tar.gz
online_test-ce995e06e3509a1340061c51dfa08a65c69eef66.tar.bz2
online_test-ce995e06e3509a1340061c51dfa08a65c69eef66.zip
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.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py11
1 files changed, 5 insertions, 6 deletions
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):