diff options
Diffstat (limited to 'yaksh')
-rw-r--r--[-rwxr-xr-x] | yaksh/code_server.py | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | yaksh/docs/sample.sh | 0 | ||||
-rw-r--r-- | yaksh/models.py | 14 | ||||
-rw-r--r-- | yaksh/pipeline/user.py | 7 | ||||
-rw-r--r-- | yaksh/settings.py | 11 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 6 | ||||
-rw-r--r-- | yaksh/templates/exam.html | 4 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 38 | ||||
-rw-r--r-- | yaksh/views.py | 7 |
9 files changed, 50 insertions, 37 deletions
diff --git a/yaksh/code_server.py b/yaksh/code_server.py index 75dd9b2..75dd9b2 100755..100644 --- a/yaksh/code_server.py +++ b/yaksh/code_server.py diff --git a/yaksh/docs/sample.sh b/yaksh/docs/sample.sh index e935cb3..e935cb3 100755..100644 --- a/yaksh/docs/sample.sh +++ b/yaksh/docs/sample.sh diff --git a/yaksh/models.py b/yaksh/models.py index 208c855..d4a73fa 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -29,10 +29,10 @@ import tempfile from textwrap import dedent from ast import literal_eval from .file_utils import extract_files, delete_files -from yaksh.code_server import(submit, - get_result as get_result_from_code_server - ) -from yaksh.settings import SERVER_POOL_PORT +from yaksh.code_server import ( + submit, get_result as get_result_from_code_server +) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from django.conf import settings from django.forms.models import model_to_dict @@ -330,7 +330,7 @@ class Quiz(models.Model): duration=30, active=True, attempts_allowed=-1, time_between_attempts=0, description='Yaksh Demo quiz', pass_criteria=0, - creator=user + creator=user, instructions="<b>This is a demo quiz.</b>" ) return demo_quiz @@ -1718,7 +1718,7 @@ class AnswerPaper(models.Model): elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() - url = 'http://localhost:%s' % server_port + url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port) submit(url, uid, json_data, user_dir) result = {'uid': uid, 'status': 'running'} return result @@ -1753,7 +1753,7 @@ class AnswerPaper(models.Model): server_port=server_port ) if question.type == "code": - url = 'http://localhost:%s' % server_port + url = '{0}:{1}'.format(SERVER_HOST_NAME, server_port) check_result = get_result_from_code_server(url, result['uid'], block=True ) diff --git a/yaksh/pipeline/user.py b/yaksh/pipeline/user.py index 4aecd95..d5ec292 100644 --- a/yaksh/pipeline/user.py +++ b/yaksh/pipeline/user.py @@ -1,8 +1,11 @@ from yaksh.models import Profile -#from django.contrib.auth.models import User + def save_profile(backend, user, response, *args, **kwargs): if not hasattr(user, 'profile'): profile = Profile.objects.create(user=user) profile.roll_number = profile.id - profile.save() + else: + profile = Profile.objects.get(user=user) + profile.is_email_verified = True + profile.save() diff --git a/yaksh/settings.py b/yaksh/settings.py index d500d93..d895d19 100644 --- a/yaksh/settings.py +++ b/yaksh/settings.py @@ -2,16 +2,21 @@ settings for yaksh app. """ +from decouple import config + # The number of code server processes to run.. -N_CODE_SERVERS = 5 +N_CODE_SERVERS = config('N_CODE_SERVERS', default=5, cast=int) # The server pool port. This is the server which returns available server # ports so as to minimize load. This is some random number where no other # service is running. It should be > 1024 and less < 65535 though. -SERVER_POOL_PORT = 53579 +SERVER_POOL_PORT = config('SERVER_POOL_PORT', default=55555, cast=int) + +SERVER_HOST_NAME = config('SERVER_HOST_NAME', default='http://localhost') +#'localhost' # Timeout for the code to run in seconds. This is an integer! -SERVER_TIMEOUT = 4 +SERVER_TIMEOUT = config('SERVER_TIMEOUT', default=4, cast=int) # The root of the URL, for example you might be in the situation where you # are not hosted as host.org/exam/ but as host.org/foo/exam/ for whatever diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index f98ab12..ec2391a 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -37,7 +37,9 @@ function unlock_screen() { } function show_solution() { - document.getElementById("solution").style.display = "block"; + var solution = document.getElementById("solution"); + solution.style.display = "block"; + solution.className ="well well-sm"; document.getElementById("skip_ex").style.visibility = "visible"; } @@ -164,7 +166,7 @@ if (question_type == 'upload' || question_type == 'code') { var data = $(this).serializeArray(); } else if (question_type == "upload"){ - var data = new FormData(getElementById("code")); + var data = new FormData(document.getElementById("code")); } ajax_check_code($(this).attr("action"), "POST", "html", data, null) e.preventDefault(); // To stop the default form submission. diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html index ce1d3b8..012adbe 100644 --- a/yaksh/templates/exam.html +++ b/yaksh/templates/exam.html @@ -60,6 +60,10 @@ {% else %} {% if qid.id == question.id %} <li class="active"><a style="width:25%" data-toggle="tooltip" title="{{ qid.description|striptags }}">{{ forloop.counter }}</a></li> + {% elif qid in paper.get_questions_answered %} + <li><a style="background-color:#B4B8BA; width:25%" href="#" data-toggle="tooltip" + onclick="call_skip('{{ URL_ROOT }}/exam/{{ question.id }}/skip/{{ qid.id }}/{{ paper.attempt_number }}/{{ module.id }}/{{ paper.question_paper.id }}/{{course.id}}/')" + title="{{ qid.description }}">{{ forloop.counter }}</a></li> {% else %} <li class="disabled"><a style="width:25%" data-toggle="tooltip" title="{{ qid.description|striptags }}">{{ forloop.counter }}</a></li> {% endif %} diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 96c8e6e..9d6ce48 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -151,21 +151,6 @@ question_type = "{{ question.type }}" {% endblock %} {% block main %} - <p id="status"></p> - {% if notification %} - {% if question.type == "code" %} - <div id="notification" class="alert alert-success" role="alert"> - <strong>Note:</strong> {{ notification }} - </div> - {% else %} - <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 }}/{{ module.id }}/{{ paper.question_paper.id }}/{{course.id}}/" method="post" enctype="multipart/form-data"> {% csrf_token %} <input type=hidden name="question_id" id="question_id" value={{ question.id }}></input> @@ -204,22 +189,20 @@ question_type = "{{ question.type }}" <h5><a href="{{f_name.file.url}}">{{f_name.file.name}}</a></h5> {% endfor %} {% endif %} - + </div> + <br/> {% if quiz.is_exercise %} {% if can_skip %} - <div id="solution"> + <div class = "well well-sm" id="solution"> {% else %} <div id="solution" style="display:none"> {% endif %} {% if question.solution %} <h4><u> Solution by teacher</u></h4> - {% else %} - <h4><u> No solution provided by teacher </u></h4> {% endif%} <font size=3 face=arial> {{ question.solution|safe }} </font> </div> {% endif %} - </div> <div class="panel-body"> {% if question.type == "mcq" %} {% for test_case in test_cases %} @@ -311,6 +294,21 @@ question_type = "{{ question.type }}" </div> </div> <br/> + <p id="status"></p> + {% if notification %} + {% if question.type == "code" %} + <div id="notification" class="alert alert-success" role="alert"> + <strong>Note:</strong> {{ notification }} + </div> + {% else %} + <div id="notification" class="alert alert-warning" role="alert"> + <strong>Note:</strong> {{ notification }} + </div> + {% endif %} + {% else %} + <div id="notification" role="alert"> + </div> + {% endif %} {% if question.type == 'code' or question.type == 'upload' %} <div class="row" id="error_panel"></div> {% endif %} diff --git a/yaksh/views.py b/yaksh/views.py index 99f81b8..49249ca 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -35,7 +35,7 @@ except ImportError: from io import BytesIO as string_io import re # Local imports. -from yaksh.code_server import get_result as get_result_from_code_server, SERVER_POOL_PORT +from yaksh.code_server import get_result as get_result_from_code_server from yaksh.models import ( Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase, HookTestCase, IntegerTestCase, McqTestCase, Profile, @@ -51,6 +51,7 @@ from yaksh.forms import ( UploadFileForm, get_object_form, FileForm, QuestionPaperForm, LessonForm, LessonFileForm, LearningModuleForm, ExerciseForm ) +from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT from .file_utils import extract_files, is_csv from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail @@ -784,7 +785,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, ) if current_question.type in ['code', 'upload']: if paper.time_left() <= 0 and not paper.question_paper.quiz.is_exercise: - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_details = get_result_from_code_server(url, uid, block=True) result = json.loads(result_details.get('result')) next_question, error_message, paper = _update_paper(request, uid, @@ -809,7 +810,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, @csrf_exempt def get_result(request, uid, course_id, module_id): result = {} - url = 'http://localhost:%s' % SERVER_POOL_PORT + url = '{0}:{1}'.format(SERVER_HOST_NAME, SERVER_POOL_PORT) result_state = get_result_from_code_server(url, uid) result['status'] = result_state.get('status') if result['status'] == 'done': |