diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 15 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 7 | ||||
-rw-r--r-- | yaksh/views.py | 7 |
3 files changed, 20 insertions, 9 deletions
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index 9d023cc..b637928 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -3,9 +3,15 @@ function submitRequest(){ document.forms["code"].submit(); } -function check_state(state, uid, success) { - if (state == "running") { +function check_state(state, uid) { + if (state == "running" || state == "not started") { setTimeout(get_result(uid), 2000); + } else if (state == "unknown") { + request_status = "initial"; + var $notice = document.getElementById("notification"); + $notice.classList.add("alert"); + $notice.classList.add("alert-success"); + $notice.innerHTML = "Your are requesting for a wrong data"; } } @@ -24,7 +30,7 @@ function get_result(uid){ } else if(content_type.includes("application/json")) { res = JSON.parse(data); request_status = res.status; - check_state(request_status, uid, res.success); + check_state(request_status, uid); } } }); @@ -74,6 +80,7 @@ $(document).ready(function(){ success: function(data, status, xhr) { content_type = xhr.getResponseHeader("content-type"); if(content_type.includes("text/html")) { + request_status = "initial" document.open(); document.write(data); document.close(); @@ -81,7 +88,7 @@ $(document).ready(function(){ res = JSON.parse(data); var uid = res.uid; request_status = res.state; - check_state(request_status, uid, false); + check_state(request_status, uid); } } }); diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 9df2fef..9789d25 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -101,14 +101,17 @@ lang = "{{ question.language }}" <p id="status"></p> {% if notification %} {% if question.type == "code" %} - <div class="alert alert-success" role="alert"> + <div id="notification" class="alert alert-success" role="alert"> <strong>Note:</strong> {{ notification }} </div> {% else %} - <div class="alert alert-warning" role="alert"> + <div id="notification" class="alert alert-warning" role="alert"> <strong>Note:</strong> {{ notification }} </div> {% endif %} + {% else %} + <div id="notification" role="alert"> + </div> {% endif %} <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" method="post" enctype="multipart/form-data"> {% csrf_token %} diff --git a/yaksh/views.py b/yaksh/views.py index f6243a7..0e9835d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -562,12 +562,13 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): @csrf_exempt def get_results(request, uid): + result = {} url = 'http://localhost:%s' % SERVER_POOL_PORT result_state = get_result(url, uid) - result = json.loads(result_state.get('result')) - next_question, error_message, paper = _update_paper(request, uid, result) result['status'] = result_state.get('status') - if result['status']== 'done': + if result['status'] == 'done': + result = json.loads(result_state.get('result')) + next_question, error_message, paper = _update_paper(request, uid, result) return show_question(request, next_question, paper, error_message) return JsonResponse(result) |