diff options
author | Prabhu Ramachandran | 2014-07-02 13:58:21 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2014-07-02 13:58:21 +0530 |
commit | ba6308eb5dfe391305f5466fba00be46a4755f7e (patch) | |
tree | e29e4e5d3cd6c4a275b1421af6551cc37efc550e /testapp/exam/views.py | |
parent | f077e3c60174884ec837dae7d58c01de49d0a2a6 (diff) | |
parent | 2e1a56c7d485b17dbeadf7458332c2e33a84f00e (diff) | |
download | online_test-ba6308eb5dfe391305f5466fba00be46a4755f7e.tar.gz online_test-ba6308eb5dfe391305f5466fba00be46a4755f7e.tar.bz2 online_test-ba6308eb5dfe391305f5466fba00be46a4755f7e.zip |
Merge pull request #31 from hardythe1/User-Dashboard
User dashboard
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r-- | testapp/exam/views.py | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py index c58ce89..6c29107 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -131,30 +131,60 @@ def user_register(request): context_instance=ci) -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} +def quizlist_user(request): + """Show All Quizzes that is available to logged-in user.""" + user = request.user + avail_quizzes = list(QuestionPaper.objects.filter(quiz__active=True)) + user_answerpapers = AnswerPaper.objects.filter(user=user) + quizzes_taken = [] + pre_requisites = [] + context = {} + + + if 'cannot_attempt' in request.GET: + context['cannot_attempt'] = True + + if user_answerpapers.count() == 0: + context['quizzes'] = avail_quizzes + context['user'] = user + context['quizzes_taken'] = None + return my_render_to_response("exam/quizzes_user.html", context) + + for answer_paper in user_answerpapers: + for quiz in avail_quizzes: + if answer_paper.question_paper.id == quiz.id and \ + answer_paper.end_time != answer_paper.start_time: + avail_quizzes.remove(quiz) + quizzes_taken.append(answer_paper) + + context['quizzes'] = avail_quizzes + context['user'] = user + context['quizzes_taken'] = quizzes_taken return my_render_to_response("exam/quizzes_user.html", context) def intro(request, questionpaper_id): """Show introduction page before quiz starts""" user = request.user + ci = RequestContext(request) + quest_paper = QuestionPaper.objects.get(id=questionpaper_id) + if quest_paper.quiz.prerequisite: + try: + pre_quest = QuestionPaper.objects.get(quiz=quest_paper.quiz.prerequisite) + answer_paper = AnswerPaper.objects.get( + question_paper=pre_quest, + user=user) + if answer_paper.passed: + context = {'user': user, 'paper_id': questionpaper_id} + return my_render_to_response('exam/intro.html', context, + context_instance=ci) + else: + context = {'user': user, 'cannot_attempt':True} + return my_redirect("/exam/quizzes/?cannot_attempt=True") + + except: + context = {'user': user, 'cannot_attempt':True} + return my_redirect("/exam/quizzes/?cannot_attempt=True") context = {'user': user, 'paper_id': questionpaper_id} ci = RequestContext(request) return my_render_to_response('exam/intro.html', context, |