From a9d7b48b6a5a79bf619500463d89f03e8ca1b7bb Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 4 Apr 2017 13:00:41 +0530 Subject: Kills stray processes in code, hook and stdio evaluator --- yaksh/base_evaluator.py | 5 +++-- yaksh/bash_stdio_evaluator.py | 3 ++- yaksh/cpp_stdio_evaluator.py | 3 ++- yaksh/hook_evaluator.py | 7 +++++-- yaksh/java_stdio_evaluator.py | 3 ++- yaksh/stdio_evaluator.py | 13 ++++++++++--- 6 files changed, 24 insertions(+), 10 deletions(-) (limited to 'yaksh') diff --git a/yaksh/base_evaluator.py b/yaksh/base_evaluator.py index 071008f..653aef0 100644 --- a/yaksh/base_evaluator.py +++ b/yaksh/base_evaluator.py @@ -7,6 +7,7 @@ from os.path import join, isfile from os.path import isdir, dirname, abspath, join, isfile, exists import subprocess import stat +import signal # Local imports @@ -30,11 +31,11 @@ class BaseEvaluator(object): stdout and stderr. """ try: - proc = subprocess.Popen(cmd_args, *args, **kw) + proc = subprocess.Popen(cmd_args,preexec_fn=os.setpgrp, *args, **kw) stdout, stderr = proc.communicate() except TimeoutException: # Runaway code, so kill it. - proc.kill() + os.killpg(os.getpgid(proc.pid), signal.SIGTERM) # Re-raise exception. raise return proc, stdout.decode('utf-8'), stderr.decode('utf-8') diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py index 334620d..1ce729a 100644 --- a/yaksh/bash_stdio_evaluator.py +++ b/yaksh/bash_stdio_evaluator.py @@ -49,7 +49,8 @@ class BashStdIOEvaluator(StdIOEvaluator): shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + preexec_fn=os.setpgrp ) success, err = self.evaluate_stdio(self.user_answer, proc, self.expected_input, diff --git a/yaksh/cpp_stdio_evaluator.py b/yaksh/cpp_stdio_evaluator.py index b302fa4..d211bb7 100644 --- a/yaksh/cpp_stdio_evaluator.py +++ b/yaksh/cpp_stdio_evaluator.py @@ -82,7 +82,8 @@ class CppStdIOEvaluator(StdIOEvaluator): shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + preexec_fn=os.setpgrp ) success, err = self.evaluate_stdio(self.user_answer, proc, self.expected_input, diff --git a/yaksh/hook_evaluator.py b/yaksh/hook_evaluator.py index 0819ec9..b86640c 100644 --- a/yaksh/hook_evaluator.py +++ b/yaksh/hook_evaluator.py @@ -7,7 +7,8 @@ import os from .file_utils import copy_files, delete_files from .base_evaluator import BaseEvaluator from .grader import TimeoutException - +import signal +import psutil class HookEvaluator(BaseEvaluator): def __init__(self, metadata, test_case_data): @@ -65,10 +66,12 @@ class HookEvaluator(BaseEvaluator): check = hook_scope["check_answer"] success, err, mark_fraction = check(self.user_answer) except TimeoutException: + processes = psutil.Process(os.getpid()).children(recursive=True) + for process in processes: + process.kill() raise except Exception: msg = traceback.format_exc(limit=0) err = "Error in Hook code: {0}".format(msg) del tb return success, err, mark_fraction - \ No newline at end of file diff --git a/yaksh/java_stdio_evaluator.py b/yaksh/java_stdio_evaluator.py index 48f265d..4e9238f 100644 --- a/yaksh/java_stdio_evaluator.py +++ b/yaksh/java_stdio_evaluator.py @@ -67,7 +67,8 @@ class JavaStdIOEvaluator(StdIOEvaluator): shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + preexec_fn=os.setpgrp ) success, err = self.evaluate_stdio(self.user_answer, proc, self.expected_input, diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index fa78a68..ec69851 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -2,6 +2,9 @@ from __future__ import unicode_literals # Local imports from .base_evaluator import BaseEvaluator +from .grader import TimeoutException +import os +import signal class StdIOEvaluator(BaseEvaluator): @@ -9,9 +12,13 @@ class StdIOEvaluator(BaseEvaluator): success = False ip = expected_input.replace(",", " ") encoded_input = '{0}\n'.format(ip).encode('utf-8') - user_output_bytes, output_err_bytes = proc.communicate(encoded_input) - user_output = user_output_bytes.decode('utf-8') - output_err = output_err_bytes.decode('utf-8') + try: + user_output_bytes, output_err_bytes = proc.communicate(encoded_input) + user_output = user_output_bytes.decode('utf-8') + output_err = output_err_bytes.decode('utf-8') + except TimeoutException: + os.killpg(os.getpgid(proc.pid), signal.SIGTERM) + raise expected_output = expected_output.replace("\r", "") if not expected_input: error_msg = "Expected Output is\n{0} ".\ -- cgit From 4ab90db99afafcf3d6ab91deeaf35e5f4874502b Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 13 Apr 2017 09:41:43 +0530 Subject: added test case to check for stray processes --- yaksh/base_evaluator.py | 2 +- yaksh/evaluator_tests/test_bash_evaluation.py | 8 ++++++++ yaksh/evaluator_tests/test_c_cpp_evaluation.py | 10 ++++++++++ yaksh/evaluator_tests/test_java_evaluation.py | 12 ++++++++++++ yaksh/evaluator_tests/test_scilab_evaluation.py | 6 +++++- 5 files changed, 36 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/base_evaluator.py b/yaksh/base_evaluator.py index 653aef0..e702f68 100644 --- a/yaksh/base_evaluator.py +++ b/yaksh/base_evaluator.py @@ -35,7 +35,7 @@ class BaseEvaluator(object): stdout, stderr = proc.communicate() except TimeoutException: # Runaway code, so kill it. - os.killpg(os.getpgid(proc.pid), signal.SIGTERM) + os.killpg(os.getpgid(proc.pid), signal.SIGKILL) # Re-raise exception. raise return proc, stdout.decode('utf-8'), stderr.decode('utf-8') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 482d45e..ee6949d 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -3,6 +3,8 @@ import unittest import os import shutil import tempfile +from psutil import Process, pid_exists +# Local Imports from yaksh.grader import Grader from yaksh.bash_code_evaluator import BashCodeEvaluator from yaksh.bash_stdio_evaluator import BashStdIOEvaluator @@ -103,6 +105,12 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + + def test_file_based_assert(self): # Given diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 304f1cb..d3147f5 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -4,6 +4,7 @@ import os import shutil import tempfile from textwrap import dedent +from psutil import Process # Local import from yaksh.grader import Grader @@ -151,6 +152,11 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + def test_file_based_assert(self): # Given @@ -401,6 +407,10 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) def test_only_stdout(self): # Given diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 3d127af..2c49a50 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -4,6 +4,9 @@ import os import shutil import tempfile from textwrap import dedent +from psutil import Process, pid_exists +import time + # Local Import from yaksh import grader as gd @@ -158,6 +161,10 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) def test_file_based_assert(self): # Given @@ -398,6 +405,11 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + def test_only_stdout(self): # Given diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index 5a452a3..1792937 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -8,7 +8,7 @@ from yaksh import grader as gd from yaksh.grader import Grader from yaksh.scilab_code_evaluator import ScilabCodeEvaluator from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest - +from psutil import Process class ScilabEvaluationTestCases(EvaluatorBaseTest): def setUp(self): @@ -136,6 +136,10 @@ class ScilabEvaluationTestCases(EvaluatorBaseTest): self.assertFalse(result.get("success")) self.assert_correct_output(self.timeout_msg, result.get("error")) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': unittest.main() -- cgit From 44754aabea4e4f59d1e8feb0894a020f146d00ef Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 19 Apr 2017 11:58:25 +0530 Subject: Allow redirection to desired page after logging in --- yaksh/views.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index db7498c..52cdc5f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -68,14 +68,14 @@ def add_to_group(users): user.groups.add(group) -def index(request): +def index(request, next_url=None): """The start page. """ user = request.user if user.is_authenticated(): if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect("/exam/quizzes/") + return my_redirect('/exam/manage/' if not next_url else next_url) + return my_redirect("/exam/quizzes/" if not next_url else next_url) return my_redirect("/exam/login/") @@ -324,27 +324,25 @@ def user_login(request): user = request.user ci = RequestContext(request) if user.is_authenticated(): - if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect("/exam/quizzes/") + return index(request) + + next_url = request.GET.get('next') if request.method == "POST": form = UserLoginForm(request.POST) if form.is_valid(): user = form.cleaned_data login(request, user) - if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') - return my_redirect('/exam/login/') + return index(request, next_url) else: context = {"form": form} - return my_render_to_response('yaksh/login.html', context, - context_instance=ci) + else: form = UserLoginForm() context = {"form": form} - return my_render_to_response('yaksh/login.html', context, - context_instance=ci) + + return my_render_to_response('yaksh/login.html', context, + context_instance=ci) -- cgit From 4603aa91a492c8b55ba66ed55780bcc4bd10c8c1 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 25 Apr 2017 19:37:21 +0530 Subject: Update docs to reflect course code changes --- yaksh/documentation/images/create_course.png | Bin 0 -> 51993 bytes yaksh/documentation/moderator_docs/creating_course.rst | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 yaksh/documentation/images/create_course.png (limited to 'yaksh') diff --git a/yaksh/documentation/images/create_course.png b/yaksh/documentation/images/create_course.png new file mode 100644 index 0000000..29c8783 Binary files /dev/null and b/yaksh/documentation/images/create_course.png differ diff --git a/yaksh/documentation/moderator_docs/creating_course.rst b/yaksh/documentation/moderator_docs/creating_course.rst index 69935fd..44ebe44 100644 --- a/yaksh/documentation/moderator_docs/creating_course.rst +++ b/yaksh/documentation/moderator_docs/creating_course.rst @@ -8,12 +8,23 @@ Setting up a new course ----------------------- To create a course, click on the Add New Course button on the moderator's dashboard. This will lead you to a create add course page, where you need to fill in the following fields. + .. image:: ../images/create_course.png + * Name Name of the Course - * Active - If the course should be active for students to take the quiz. The status of the course can be edited later. * Enrollment Open enrollment is open to all students. Enroll Request requires students to send a request which the moderator can accept or reject. + * Active + If the course should be active for students to take the quiz. The status of the course can be edited later. + * Code + If the course should be hidden and only accessible to students possessing the correct course code. + * Instructions + Instructions for the course + * Start Date and Time for enrollment of course + If the enrollment of the course should be available only after a set date and time + * End Date and Time for enrollment of course + If the enrollment of the course should be available only before a set date and time + Features in Courses ------------------- -- cgit From c431c255738b741698adffcbf894930ae298b8c0 Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 27 Apr 2017 12:13:22 +0530 Subject: added tests to check killing of stray processes in hook evaluator --- yaksh/evaluator_tests/test_bash_evaluation.py | 5 +++++ yaksh/evaluator_tests/test_c_cpp_evaluation.py | 5 ++++- yaksh/evaluator_tests/test_java_evaluation.py | 5 +++++ yaksh/hook_evaluator.py | 5 +++-- 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index ee6949d..352e95f 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -536,6 +536,11 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) + if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index d3147f5..79227f5 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -977,7 +977,10 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest): # Then self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) - + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 2c49a50..39c5ee9 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -844,8 +844,13 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest): result = grader.evaluate(kwargs) # Then + self.assertFalse(result.get('success')) self.assert_correct_output(self.timeout_msg, result.get('error')) + parent_proc = Process(os.getpid()).children() + if parent_proc: + self.assertFalse(any(Process(parent_proc[0].pid)\ + .children(recursive=True))) if __name__ == '__main__': diff --git a/yaksh/hook_evaluator.py b/yaksh/hook_evaluator.py index b86640c..f5364d6 100644 --- a/yaksh/hook_evaluator.py +++ b/yaksh/hook_evaluator.py @@ -2,13 +2,14 @@ import sys import traceback import os +import signal +import psutil # Local imports from .file_utils import copy_files, delete_files from .base_evaluator import BaseEvaluator from .grader import TimeoutException -import signal -import psutil + class HookEvaluator(BaseEvaluator): def __init__(self, metadata, test_case_data): -- cgit From 4a8f9a117f6a784fe722b8b381368c41be86024a Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 27 Apr 2017 12:51:10 +0530 Subject: made pep8 changes --- yaksh/evaluator_tests/test_bash_evaluation.py | 11 ++++------- yaksh/evaluator_tests/test_c_cpp_evaluation.py | 14 +++++++------- yaksh/evaluator_tests/test_java_evaluation.py | 13 ++++++------- yaksh/evaluator_tests/test_scilab_evaluation.py | 9 ++++++--- yaksh/stdio_evaluator.py | 4 ++-- 5 files changed, 25 insertions(+), 26 deletions(-) (limited to 'yaksh') diff --git a/yaksh/evaluator_tests/test_bash_evaluation.py b/yaksh/evaluator_tests/test_bash_evaluation.py index 352e95f..8bb8c81 100644 --- a/yaksh/evaluator_tests/test_bash_evaluation.py +++ b/yaksh/evaluator_tests/test_bash_evaluation.py @@ -107,10 +107,8 @@ class BashAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -538,9 +536,8 @@ class BashHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_c_cpp_evaluation.py b/yaksh/evaluator_tests/test_c_cpp_evaluation.py index 79227f5..b15f766 100644 --- a/yaksh/evaluator_tests/test_c_cpp_evaluation.py +++ b/yaksh/evaluator_tests/test_c_cpp_evaluation.py @@ -154,9 +154,8 @@ class CAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -409,8 +408,8 @@ class CppStdIOEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_only_stdout(self): # Given @@ -979,8 +978,9 @@ class CppHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/evaluator_tests/test_java_evaluation.py b/yaksh/evaluator_tests/test_java_evaluation.py index 39c5ee9..ea558ed 100644 --- a/yaksh/evaluator_tests/test_java_evaluation.py +++ b/yaksh/evaluator_tests/test_java_evaluation.py @@ -163,8 +163,8 @@ class JavaAssertionEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_file_based_assert(self): # Given @@ -407,9 +407,8 @@ class JavaStdIOEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) - + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) def test_only_stdout(self): # Given @@ -849,8 +848,8 @@ class JavaHookEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get('error')) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) if __name__ == '__main__': diff --git a/yaksh/evaluator_tests/test_scilab_evaluation.py b/yaksh/evaluator_tests/test_scilab_evaluation.py index 1792937..c3a1c83 100644 --- a/yaksh/evaluator_tests/test_scilab_evaluation.py +++ b/yaksh/evaluator_tests/test_scilab_evaluation.py @@ -3,12 +3,14 @@ import unittest import os import shutil import tempfile +from psutil import Process from textwrap import dedent + +#Local Import from yaksh import grader as gd from yaksh.grader import Grader from yaksh.scilab_code_evaluator import ScilabCodeEvaluator from yaksh.evaluator_tests.test_python_evaluation import EvaluatorBaseTest -from psutil import Process class ScilabEvaluationTestCases(EvaluatorBaseTest): def setUp(self): @@ -138,8 +140,9 @@ class ScilabEvaluationTestCases(EvaluatorBaseTest): self.assert_correct_output(self.timeout_msg, result.get("error")) parent_proc = Process(os.getpid()).children() if parent_proc: - self.assertFalse(any(Process(parent_proc[0].pid)\ - .children(recursive=True))) + children_procs = Process(parent_proc[0].pid) + self.assertFalse(any(children_procs.children(recursive=True))) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/stdio_evaluator.py b/yaksh/stdio_evaluator.py index ec69851..554d4c5 100644 --- a/yaksh/stdio_evaluator.py +++ b/yaksh/stdio_evaluator.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals +import os +import signal # Local imports from .base_evaluator import BaseEvaluator from .grader import TimeoutException -import os -import signal class StdIOEvaluator(BaseEvaluator): -- cgit From 290b71a311ad245b996f38bc7da4080a07493958 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 5 Apr 2017 18:50:00 +0530 Subject: Add course_code field allows access only to users with relevant course code string --- yaksh/forms.py | 11 +++++++++++ yaksh/models.py | 4 ++++ yaksh/templates/yaksh/quizzes_user.html | 19 +++++++++++++++++-- yaksh/views.py | 23 +++++++++++++++++------ 4 files changed, 49 insertions(+), 8 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index f7f7a10..1306e7d 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -274,6 +274,17 @@ class QuestionFilterForm(forms.Form): class CourseForm(forms.ModelForm): """ course form for moderators """ + def save(self, commit=True, *args, **kwargs): + instance = super(CourseForm, self).save(commit=False) + if instance.code: + instance.hidden = True + else: + instance.hidden = False + + if commit: + instance.save() + return instance + class Meta: model = Course exclude = ['creator', 'requests', 'students', 'rejected', diff --git a/yaksh/models.py b/yaksh/models.py index 6646615..35375e0 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -112,6 +112,8 @@ class CourseManager(models.Manager): trial_course.enroll(False, user) return trial_course + def get_hidden_courses(self, code): + return self.filter(code=code, hidden=True) ############################################################################### class Course(models.Model): @@ -119,6 +121,8 @@ class Course(models.Model): name = models.CharField(max_length=128) enrollment = models.CharField(max_length=32, choices=enrollment_methods) active = models.BooleanField(default=True) + code = models.CharField(max_length=128, null=True, blank=True) + hidden = models.BooleanField(default=False) creator = models.ForeignKey(User, related_name='creator') students = models.ManyToManyField(User, related_name='students') requests = models.ManyToManyField(User, related_name='requests') diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index ce74844..c34138f 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -1,6 +1,21 @@ {% extends "user.html" %} {% block pagetitle %} {{ title }} {% endblock %} {% block main %} +