diff options
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/models.py | 3 | ||||
-rw-r--r-- | testapp/exam/urls.py | 9 | ||||
-rw-r--r-- | testapp/exam/views.py | 87 | ||||
-rw-r--r-- | testapp/templates/exam/add_quiz.html | 8 | ||||
-rw-r--r-- | testapp/templates/exam/automatic_questionpaper.html | 2 | ||||
-rw-r--r-- | testapp/templates/exam/complete.html | 2 | ||||
-rw-r--r-- | testapp/templates/exam/intro.html | 2 | ||||
-rw-r--r-- | testapp/templates/exam/question.html | 6 | ||||
-rw-r--r-- | testapp/templates/exam/quit.html | 3 | ||||
-rw-r--r-- | testapp/templates/exam/quizzes_user.html | 18 | ||||
-rw-r--r-- | testapp/templates/exam/results_user.html | 23 | ||||
-rw-r--r-- | testapp/templates/user.html | 58 |
12 files changed, 186 insertions, 35 deletions
diff --git a/testapp/exam/models.py b/testapp/exam/models.py index dd0c033..04789da 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -129,6 +129,9 @@ class AnswerPaper(models.Model): # The time when this paper was started by the user. start_time = models.DateTimeField() + + # The time when this paper was ended by the user. + end_time = models.DateTimeField() # User's IP which is logged. user_ip = models.CharField(max_length=15) diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index e7284f2..ff1545a 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -3,13 +3,18 @@ from django.conf.urls.defaults import patterns, include, url urlpatterns = patterns('exam.views', url(r'^$', 'index'), url(r'^login/$', 'user_login'), + url(r'^quizzes/$','quizlist_user'), + url(r'^results/$','results_user'), url(r'^start/$', 'start'), - url(r'^quit/$', 'quit'), + url(r'^start/(?P<questionpaper_id>\d+)/$','start'), + url(r'^quit/(?P<answerpaper_id>\d+)/$', 'quit'), url(r'^intro/$','start'), - url(r'^complete/$', 'complete'), + url(r'^complete/$', 'complete'), + url(r'^complete/(?P<answerpaper_id>\d+)/$', 'complete'), url(r'^register/$', 'user_register'), url(r'^(?P<q_id>\d+)/$', 'question'), url(r'^(?P<q_id>\d+)/check/$', 'check'), + url(r'^(?P<q_id>\d+)/check/(?P<questionpaper_id>\d+)/$', 'check'), url(r'^manage/$', 'prof_manage'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 5e594b2..e485241 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -94,6 +94,38 @@ def user_register(request): {'form':form}, context_instance=RequestContext(request)) +def quizlist_user(request): + """Show All Quizzes that is available to logged-in user.""" + user=request.user + avail_quiz = list(QuestionPaper.objects.filter(quiz__active=True)) + user_answerpapers = AnswerPaper.objects.filter(user=user) + user_quiz = [] + + if user_answerpapers.count() == 0: + context = {'quizzes':avail_quiz} + return my_render_to_response("exam/quizzes_user.html",context) + + for paper in user_answerpapers: + for quiz in avail_quiz: + if paper.question_paper.id == quiz.id and paper.end_time != paper.start_time: + avail_quiz.remove(quiz) + + context = {'quizzes':avail_quiz,'user':user} + return my_render_to_response("exam/quizzes_user.html",context) + +def results_user(request): + """Show list of Results of Quizzes that is taken by logged-in user.""" + user = request.user + papers = AnswerPaper.objects.filter(user=user) + quiz_marks = [] + for paper in papers: + temp = [] + temp.append(paper.question_paper.quiz.description) + temp.append(paper.get_total_marks()) + quiz_marks.append(temp) + context = {'papers':quiz_marks} + return my_render_to_response("exam/results_user.html",context) + def edit_quiz(request): """Edit the list of quizzes seleted by the user for editing.""" @@ -128,7 +160,7 @@ def edit_quiz(request): def edit_question(request): """Edit the list of questions seleted by the user for editing.""" user = request.user - if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') summary = request.POST.getlist('summary') @@ -581,23 +613,24 @@ def user_login(request): return my_render_to_response('exam/login.html', context, context_instance=RequestContext(request)) -def start(request): +def start(request,questionpaper_id=None): """Check the user cedentials and if any quiz is available, start the exam.""" - user = request.user + if questionpaper_id == None: + return my_redirect('/exam/quizzes/') try: # Right now the app is designed so there is only one active quiz # at a particular time. - questionpaper = QuestionPaper.objects.all()[0] + questionpaper = QuestionPaper.objects.get(id=questionpaper_id) except QuestionPaper.DoesNotExist: msg = 'Quiz not found, please contact your '\ 'instructor/administrator. Please login again thereafter.' return complete(request, reason=msg) try: - old_paper = AnswerPaper.objects.get(user=user, question_paper=questionpaper) + old_paper = AnswerPaper.objects.get(question_paper=questionpaper, user=user) q = old_paper.current_question() - return show_question(request, q) + return show_question(request, q,questionpaper_id) except AnswerPaper.DoesNotExist: ip = request.META['REMOTE_ADDR'] key = gen_key(10) @@ -610,7 +643,7 @@ def start(request): new_paper = AnswerPaper(user=user, user_ip=ip, question_paper=questionpaper, profile=profile) new_paper.start_time = datetime.datetime.now() - + new_paper.end_time = datetime.datetime.now() # Make user directory. user_dir = get_user_dir(user) @@ -623,12 +656,12 @@ def start(request): new_paper.save() # Show the user the intro page. - context = {'user': user} + context = {'user': user,'paper_id':questionpaper_id} ci = RequestContext(request) return my_render_to_response('exam/intro.html', context, context_instance=ci) -def question(request, q_id): +def question(request, q_id, questionpaper_id): """Check the credentials of the user and start the exam.""" user = request.user @@ -636,10 +669,10 @@ def question(request, q_id): return my_redirect('/exam/login/') q = get_object_or_404(Question, pk=q_id) try: - q_paper = QuestionPaper.objects.get(quiz__active=True) + q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=request.user, question_paper=q_paper) except AnswerPaper.DoesNotExist: - return my_redirect('/exam/start') + return my_redirect('/exam/start/') if not paper.question_paper.quiz.active: return complete(request, reason='The quiz has been deactivated!') @@ -654,29 +687,29 @@ def question(request, q_id): return my_render_to_response('exam/question.html', context, context_instance=ci) -def show_question(request, q_id): +def show_question(request, q_id, questionpaper_id): """Show a question if possible.""" if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' return complete(request, msg) else: - return question(request, q_id) + return question(request, q_id, questionpaper_id) -def check(request, q_id): +def check(request, q_id, questionpaper_id=None): """Checks the answers of the user for particular question""" user = request.user if not user.is_authenticated(): return my_redirect('/exam/login/') question = get_object_or_404(Question, pk=q_id) - q_paper = QuestionPaper.objects.get(quiz__active=True) + q_paper = QuestionPaper.objects.get(id=questionpaper_id) paper = AnswerPaper.objects.get(user=request.user,question_paper = q_paper) answer = request.POST.get('answer') skip = request.POST.get('skip', None) if skip is not None: next_q = paper.skip() - return show_question(request, next_q) + return show_question(request, next_q,questionpaper_id) # Add the answer submitted, regardless of it being correct or not. new_answer = Answer(question=question, answer=answer, correct=False) @@ -723,17 +756,22 @@ def check(request, q_id): context_instance=ci) else: next_q = paper.completed_question(question.id) - return show_question(request, next_q) + return show_question(request, next_q,questionpaper_id) -def quit(request): +def quit(request, answerpaper_id=None): """Show the quit page when the user logs out.""" + context = { 'id':answerpaper_id} + return my_render_to_response('exam/quit.html',context,context_instance=RequestContext(request)) - return my_render_to_response('exam/quit.html',context_instance=RequestContext(request)) - -def complete(request,reason = None): +def complete(request,reason = None,answerpaper_id=None): """Show a page to inform user that the quiz has been compeleted.""" user = request.user + + if answerpaper_id == None: + logout(request) + context = {'message': "You are successfully Logged out."} + return my_render_to_response('exam/complete.html', context) no = False message = reason or 'The quiz has been completed. Thank you.' if user.groups.filter(name='moderator').count() > 0: @@ -742,9 +780,10 @@ def complete(request,reason = None): no = True if not no: # Logout the user and quit with the message given. - logout(request) - context = {'message': message} - return my_render_to_response('exam/complete.html', context) + answer_paper = AnswerPaper.objects.get(id=answerpaper_id) + answer_paper.endtime = datetime.datetime.now() + answer_paper.save() + return my_redirect('/exam/quizzes/') else: return my_redirect('/exam/') diff --git a/testapp/templates/exam/add_quiz.html b/testapp/templates/exam/add_quiz.html index c8e1ac3..2667c0c 100644 --- a/testapp/templates/exam/add_quiz.html +++ b/testapp/templates/exam/add_quiz.html @@ -13,7 +13,11 @@ <script type='text/javascript'> function test() { - document.getElementById('id_description').onFocus="javascript:test2()"; + + if (document.getElementById("id_description").value != "") + { + document.getElementById("submit").innerHTML = "Save"; + } } </script> @@ -28,7 +32,7 @@ </table> </center> - <center><button class="btn" type="submit" name="questionpaper">Design Question Paper</button> + <center><button class="btn" type="submit" id="submit" name="questionpaper">Design Question Paper</button> <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/showquiz/");'>Cancel</button> </center> </form> {% endblock %} diff --git a/testapp/templates/exam/automatic_questionpaper.html b/testapp/templates/exam/automatic_questionpaper.html index b961711..b8f76b4 100644 --- a/testapp/templates/exam/automatic_questionpaper.html +++ b/testapp/templates/exam/automatic_questionpaper.html @@ -34,7 +34,7 @@ function load_data() {% endblock %} {% block manage %} -<center><b>Automotic mode to design the Question Paper</center><br> +<center><b>Automatic mode to design the Question Paper</center><br> <form action="" method="post" name=frm> {% csrf_token %} diff --git a/testapp/templates/exam/complete.html b/testapp/templates/exam/complete.html index a2e673b..1d5df3c 100644 --- a/testapp/templates/exam/complete.html +++ b/testapp/templates/exam/complete.html @@ -4,7 +4,7 @@ {% block pagetitle %}Online Test{% endblock %} {% block content %} - +{% csrf_token %} <center><h2> Good bye! </h2></center> <center><h4> {{message}} </h4></center> <center><h4>You may now close the browser.</h4></center><br> diff --git a/testapp/templates/exam/intro.html b/testapp/templates/exam/intro.html index afa596b..ec1888a 100644 --- a/testapp/templates/exam/intro.html +++ b/testapp/templates/exam/intro.html @@ -27,7 +27,7 @@ </ul> <p> We hope you enjoy taking this exam !!!</p> - <form action="{{URL_ROOT}}/exam/start/" method="post" align="center"> + <form action="{{URL_ROOT}}/exam/start/{{ paper_id }}/" method="post" align="center"> {% csrf_token %} <center><button class="btn" type="submit" name="start">Start Exam!</button></center> </form> diff --git a/testapp/templates/exam/question.html b/testapp/templates/exam/question.html index 87ed40d..584ab72 100644 --- a/testapp/templates/exam/question.html +++ b/testapp/templates/exam/question.html @@ -70,9 +70,9 @@ <ul> <li> <h5><a> Hi {{user.first_name.title}} {{user.last_name.title}} </a></h5> </ul> - <form id="logout" action="{{URL_ROOT}}/exam/quit/" method="post" class="pull-right"> + <form id="logout" action="{{URL_ROOT}}/exam/quit/{{ paper.question_paper.id }}/" method="post" class="pull-right"> {% csrf_token %} - <button class="btn" type="submit" name="quit">Quit Exam and Logout</button> </li> + <button class="btn" type="submit" name="quit">Quit Exam</button> </li> </form> </div> @@ -85,7 +85,7 @@ {% if error_message %}<h5>ERROR:</h5><div class="alert alert-error">{{ error_message }}</div>{% endif %} <p id="status"></p> - <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/" method="post"> + <form id="code" action="{{URL_ROOT}}/exam/{{ question.id }}/check/{{ paper.question_paper.id }}/" method="post"> {% csrf_token %} {% if question.type == "mcq" %} {% for option in question.options.strip.splitlines %} diff --git a/testapp/templates/exam/quit.html b/testapp/templates/exam/quit.html index 40a0a92..3f7630d 100644 --- a/testapp/templates/exam/quit.html +++ b/testapp/templates/exam/quit.html @@ -6,7 +6,8 @@ <center><h4>Your current answers are saved.</h4></center> <center><h4> Are you sure you wish to quit the exam?</h4></center> - <form action="{{URL_ROOT}}/exam/complete/" method="post"> + <center><h4> Be sure, as you won't be able to restart this exam.</h4></center> + <form action="{{URL_ROOT}}/exam/complete/{{ id }}/" method="post"> {% csrf_token %} <center><button class="btn" type="submit" name="yes">Yes!</button> <button class="btn" type="submit" name="no">No!</button></center> </form> diff --git a/testapp/templates/exam/quizzes_user.html b/testapp/templates/exam/quizzes_user.html new file mode 100644 index 0000000..af2d98a --- /dev/null +++ b/testapp/templates/exam/quizzes_user.html @@ -0,0 +1,18 @@ +{% extends "user.html" %} + + +{% block subtitle %}Available Quizzes{% endblock %} + +{% block css %} +<link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/question_quiz.css" type="text/css" /> +{% endblock %} + +{% block manage %} + {% if not quizzes %} + <center><h4>No active quizzes for you</h4></center> + {% endif %} + {% for paper in quizzes %} + <a href="{{ URL_ROOT }}/exam/start/{{paper.id}}">{{ paper.quiz.description }}</a><br> + {% endfor %} +{% endblock %} + diff --git a/testapp/templates/exam/results_user.html b/testapp/templates/exam/results_user.html new file mode 100644 index 0000000..75d168d --- /dev/null +++ b/testapp/templates/exam/results_user.html @@ -0,0 +1,23 @@ +{% extends "user.html" %} + + +{% block subtitle %}Results for {{ papers.user.first_name }}{% endblock %} + +{% block css %} +<link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/question_quiz.css" type="text/css" /> +{% endblock %} + +{% block manage %} +<form action="" method="post" name=frm> + {% csrf_token %} + <center> + {% for paper in papers %} + {% for i in paper %} + {{ i }} + {% endfor %} + <br> + {% endfor %} + </center> +</form> +{% endblock %} + diff --git a/testapp/templates/user.html b/testapp/templates/user.html new file mode 100644 index 0000000..22a9fac --- /dev/null +++ b/testapp/templates/user.html @@ -0,0 +1,58 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <title> + {% block title %} + {% endblock %} + </title> + + {% block meta %} + <meta charset="utf-8"> + <meta name="description" content=""> + <meta name="author" content=""> + {% endblock %} + + <link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/base.css" type="text/css" /> + {% block css %} + {% endblock %} + + {% block script %} + {% endblock %} + </head> + +<body {% block onload %}{% endblock %}> +<div class="topbar"> + <div class="fill"> + <div class="container"> + <h3 class="brand"><strong>Online Test</h3></strong> + <ul> + <li><a href="{{ URL_ROOT }}/exam/quizzes">Quizzes</a></li> + <li><a href="{{ URL_ROOT }}/exam/results">Results</a></li> + </ul> + <ul style="float:right;"> + <li><strong><a style='cursor:pointer' onClick='location.replace("{{URL_ROOT}}/exam/complete/");'>Log out</a></strong></li> + </ul> + </div> + </div> +</div> + <div class="container"> + <div class="content"> + <div class="page-header"> + <h3><center>{% block subtitle %}Welcome {{ user.first_name.title }} {{user.last_name.title}} {% endblock %}</center></h3><br> + </div> + <div class=row> + <div class=span14> + {% block manage %} + {% endblock %} + </div> + </div> + </div> + <footer> + <p>© FOSSEE group, IIT Bombay</p> + </footer> + </div> + +</body> +</html> |