summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
Diffstat (limited to 'testapp')
-rw-r--r--testapp/exam/views.py66
-rw-r--r--testapp/templates/exam/quizzes_user.html69
2 files changed, 114 insertions, 21 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,
diff --git a/testapp/templates/exam/quizzes_user.html b/testapp/templates/exam/quizzes_user.html
index b55d3e5..914b6b4 100644
--- a/testapp/templates/exam/quizzes_user.html
+++ b/testapp/templates/exam/quizzes_user.html
@@ -1,18 +1,81 @@
{% extends "user.html" %}
-{% block subtitle %}Available Quizzes{% endblock %}
+{% block subtitle %}Hello {{ user.first_name }}, welcome to your dashboard !{% endblock %}
{% block css %}
<link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/question_quiz.css" type="text/css" />
{% endblock %}
+{% block script %}
+<script src="{{ URL_ROOT }}/static/exam/js/bootstrap-alert.js"></script>
+<script src="{{ URL_ROOT }}/static/exam/js/quizzes_user.js"></script>
+{% endblock %}
+
+
{% block manage %}
+ {% if cannot_attempt %}
+ <p>You have not passed the prerequisite & hence you cannot take the quiz.</p>
+ {% endif %}
+ <h4>List of quizzes availbale for you</h4>
{% if not quizzes %}
- <center><h4>No active quizzes for you</h4></center>
+ <h5>No active quizzes for you</h5>
{% endif %}
+ <table>
+ <th>Quiz</th>
+ <th>Pre requisite quiz</th>
{% for paper in quizzes %}
- <a href="{{ URL_ROOT }}/exam/intro/{{paper.id}}">{{ paper.quiz.description }}</a><br>
+ <tr>
+ <td>
+ <a href="{{ URL_ROOT }}/exam/intro/{{paper.id}}">{{ paper.quiz.description }}</a><br>
+ </td>
+ <td>
+ {% if paper.quiz.prerequisite %}
+ You have to pass {{ paper.quiz.prerequisite.description }} for taking {{ paper.quiz.description }}
+ {% else %}
+ No pre requisites for {{ paper.quiz.description }}
+ {% endif %}
+ </td>
+ </tr>
{% endfor %}
+ </table>
+ <hr>
+ <h4>List of quizzes taken by you so far</h4>
+ {% if quizzes_taken %}
+ <table class="bordered-table zebra-striped">
+ <th>Quiz</th>
+ <th>Result</th>
+ <th>Mraks Obtained</th>
+ <th>Total Marks</th>
+ <th>Percentage</th>
+ {% for paper in quizzes_taken %}
+ <tr>
+ <td>
+ {{ paper.question_paper.quiz.description }}
+ </td>
+ <td>
+ {% if paper.passed %}
+ <p>Pass</p>
+ {% else %}
+ <p>Fail</p>
+ {% endif %}
+ </td>
+ <td>
+ {{ paper.marks_obtained }}
+ </td>
+ <td>
+ {{ paper.question_paper.total_marks }}
+ </td>
+ <td>
+ {{ paper.percent }}
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ {% else %}
+ <p>You have not taken any quiz yet !!</p>
+ {% endif %}
+
+
{% endblock %}