diff options
author | prathamesh | 2015-01-20 17:05:41 +0530 |
---|---|---|
committer | prathamesh | 2015-01-20 17:05:41 +0530 |
commit | f2e09edeb2e5b884f0e75ad3747b51e7603d70e1 (patch) | |
tree | fac9c70feeff6e1c470097623fd54a6244f786c0 /testapp | |
parent | cbdeb90a756832c71c80bac4dbe9ba1a3aceacb2 (diff) | |
download | online_test-f2e09edeb2e5b884f0e75ad3747b51e7603d70e1.tar.gz online_test-f2e09edeb2e5b884f0e75ad3747b51e7603d70e1.tar.bz2 online_test-f2e09edeb2e5b884f0e75ad3747b51e7603d70e1.zip |
Assignment upload interface implementation
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/forms.py | 1 | ||||
-rw-r--r-- | testapp/exam/models.py | 3 | ||||
-rw-r--r-- | testapp/exam/templates/exam/question.html | 19 | ||||
-rw-r--r-- | testapp/exam/urls.py | 2 | ||||
-rw-r--r-- | testapp/exam/views.py | 30 | ||||
-rw-r--r-- | testapp/settings.py | 4 | ||||
-rw-r--r-- | testapp/urls.py | 2 |
7 files changed, 34 insertions, 27 deletions
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() <p id="status"></p> - {% if question.type == "bash assignment" %} - <form action="{{URL_ROOT}}/exam/submit-assignment/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" method="post"> - <p>Upload assignment file for the said question<p> - <input type=file id=assignment name=assignment> - <hr> - <br><button class="btn" type="submit" name="submitassign" id="submitassign">Upload</button> - <button class="btn" type="submit" name="skip" id="skip">Skip</button> - </form> - {% endif %} - - <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.attempt_number }}/{{ paper.question_paper.id }}/" method="post"> + <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 %} {% if question.type == "mcq" %} {% for option in question.options.strip.splitlines %} <input name="answer" type="radio" value="{{option}}" />{{option}} <br/> {% endfor %} {% endif %} + {% if question.type == "basgn" %} + <p>Upload assignment file for the said question<p> + <input type=file id="assignment" name="assignment"> + <hr> + {% endif %} {% if question.type == "mcc" %} {% for option in question.options.strip.splitlines %} <input name="answer" type="checkbox" value="{{ option }}"> {{ option }} @@ -134,6 +129,8 @@ function setSnippetHeight() {% if question.type == "mcq" or question.type == "mcc "%} <br><button class="btn" type="submit" name="check" id="check">Submit Answer</button> + {% elif question.type == "basgn" %} + <br><button class="btn" type="submit" name="check" id="check">Submit Answer</button> {% else %} <button class="btn" type="submit" name="check" id="check" onClick="submitCode();">Check Answer</button> {% 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 diff --git a/testapp/settings.py b/testapp/settings.py index 88d4a5a..00a6b17 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -72,12 +72,12 @@ USE_L10N = True # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = '' +MEDIA_ROOT = join(CURDIR, '../uploads') # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '' +MEDIA_URL = 'upload/' # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files diff --git a/testapp/urls.py b/testapp/urls.py index 6c19e81..dee297c 100644 --- a/testapp/urls.py +++ b/testapp/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import * # Uncomment the next two lines to enable the admin: from django.contrib import admin |