From f2e09edeb2e5b884f0e75ad3747b51e7603d70e1 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 20 Jan 2015 17:05:41 +0530 Subject: Assignment upload interface implementation --- testapp/exam/forms.py | 1 + testapp/exam/models.py | 3 ++- testapp/exam/templates/exam/question.html | 19 ++++++++----------- testapp/exam/urls.py | 2 +- testapp/exam/views.py | 30 +++++++++++++++++++----------- 5 files changed, 31 insertions(+), 24 deletions(-) (limited to 'testapp/exam') diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 169632d..843ed15 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -27,6 +27,7 @@ question_types = ( ("mcq", "Multiple Choice"), ("mcc", "Multiple Correct Choices"), ("code", "Code"), + ("basgn", "Bash Assignment"), ) UNAME_CHARS = letters + "._" + digits diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 1cafa89..88ba9ef 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -30,6 +30,7 @@ question_types = ( ("mcq", "Multiple Choice"), ("mcc", "Multiple Correct Choices"), ("code", "Code"), + ("basgn", "Bash Assignment"), ) attempts = [(i, i) for i in range(1, 6)] attempts.append((-1, 'Infinite')) @@ -42,7 +43,7 @@ test_status = ( ) def get_assignment_dir(instance, filename): - return '%s/%s/' % (instance.user.roll_number, instance.assignment.description) + return '%s/%s' % (instance.user.roll_number, instance.assignmentQuestion.id) ############################################################################### class Question(models.Model): diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html index f8888b1..03284ce 100644 --- a/testapp/exam/templates/exam/question.html +++ b/testapp/exam/templates/exam/question.html @@ -96,23 +96,18 @@ function setSnippetHeight()

- {% if question.type == "bash assignment" %} -
-

Upload assignment file for the said question

- -


-
   - -
- {% endif %} - -
+ {% csrf_token %} {% if question.type == "mcq" %} {% for option in question.options.strip.splitlines %} {{option}}
{% endfor %} {% endif %} + {% if question.type == "basgn" %} +

Upload assignment file for the said question

+ +


+ {% endif %} {% if question.type == "mcc" %} {% for option in question.options.strip.splitlines %} {{ option }} @@ -134,6 +129,8 @@ function setSnippetHeight() {% if question.type == "mcq" or question.type == "mcc "%}
   + {% elif question.type == "basgn" %} +
   {% else %}    {% endif %} diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index e32b7e1..f7a7c54 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import * urlpatterns = patterns('testapp.exam.views', url(r'^$', 'index'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 9902b74..ce1c62e 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -21,7 +21,7 @@ from testapp.exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\ QuestionForm, RandomQuestionForm from testapp.exam.xmlrpc_clients import code_server from settings import URL_ROOT - +from testapp.exam.models import AssignmentUpload # The directory where user data can be saved. OUTPUT_DIR = abspath(join(dirname(__file__), 'output')) @@ -760,6 +760,13 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): user_answer = request.POST.get('answer') elif question.type == 'mcc': user_answer = request.POST.getlist('answer') + elif question.type == 'basgn': + assign = AssignmentUpload() + assign.user = user.profile + assign.assignmentQuestion = question + assign.assignmentFile = request.FILES['assignment'] + assign.save() + user_answer = 'ASSIGNMENT UPLOADED' else: user_code = request.POST.get('answer') user_answer = snippet_code + "\n" + user_code @@ -772,15 +779,16 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): # If we were not skipped, we were asked to check. For any non-mcq # questions, we obtain the results via XML-RPC with the code executed # safely in a separate process (the code_server.py) running as nobody. - correct, success, err_msg = validate_answer(user, user_answer, question) - if correct: - new_answer.correct = correct - new_answer.marks = question.points - new_answer.error = err_msg - success_msg = True - else: - new_answer.error = err_msg - new_answer.save() + if not question.type == 'basgn': + correct, success, err_msg = validate_answer(user, user_answer, question) + if correct: + new_answer.correct = correct + new_answer.marks = question.points + new_answer.error = err_msg + success_msg = True + else: + new_answer.error = err_msg + new_answer.save() time_left = paper.time_left() if not success: # Should only happen for non-mcq questions. @@ -1204,4 +1212,4 @@ def submit_assignment(request, question_id=None): #next question ke liye code idhar else: #code for skipping the question - + pass -- cgit