summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
Diffstat (limited to 'testapp')
-rw-r--r--testapp/exam/urls.py3
-rw-r--r--testapp/exam/views.py28
-rw-r--r--testapp/templates/exam/quizlist.html24
3 files changed, 47 insertions, 8 deletions
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index 9e42093..1e1cd12 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -3,7 +3,8 @@ from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('exam.views',
url(r'^$', 'index'),
url(r'^login/$', 'user_login'),
- url(r'^start/$', 'start'),
+ url(r'^quizlist/$', 'quizlist'),
+ url(r'^start/(?P<quiz_id>\d+)/$', 'start'),
url(r'^quit/$', 'quit'),
url(r'^complete/$', 'complete'),
url(r'^register/$', 'user_register'),
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 7216f5b..a529983 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -70,7 +70,7 @@ def user_register(request):
user = request.user
if user.is_authenticated():
- return my_redirect("/exam/start/")
+ return my_redirect("/exam/quizlist/")
if request.method == "POST":
form = UserRegisterForm(request.POST)
@@ -80,7 +80,7 @@ def user_register(request):
new_user = authenticate(username = u_name, password = pwd)
login(request, new_user)
- return my_redirect("/exam/start/")
+ return my_redirect("/exam/quizlist/")
else:
return my_render_to_response('exam/register.html',
@@ -259,7 +259,7 @@ def user_login(request):
if user.is_authenticated():
if user.groups.filter(name='moderator').count() > 0 :
return my_redirect('/exam/manage/')
- return my_redirect("/exam/start/")
+ return my_redirect("/exam/quizlist/")
if request.method == "POST":
form = UserLoginForm(request.POST)
@@ -268,7 +268,7 @@ def user_login(request):
login(request, user)
if user.groups.filter(name='moderator').count() > 0 :
return my_redirect('/exam/manage/')
- return my_redirect('/exam/start/')
+ return my_redirect('/exam/login/')
else:
context = {"form": form}
return my_render_to_response('exam/login.html', context,
@@ -279,18 +279,19 @@ def user_login(request):
return my_render_to_response('exam/login.html', context,
context_instance=RequestContext(request))
-def start(request):
+def start(request,quiz_id=None):
"""Check the user cedentials and if any quiz is available, start the exam."""
user = request.user
try:
# Right now the app is designed so there is only one active quiz
# at a particular time.
- quiz = Quiz.objects.get(active=True)
+ quiz = Quiz.objects.get(id=quiz_id)
except Quiz.DoesNotExist:
- msg = 'No active quiz found, please contact your '\
+ msg = 'Quiz not found, please contact your '\
'instructor/administrator. Please login again thereafter.'
return complete(request, reason=msg)
+
try:
old_paper = QuestionPaper.objects.get(user=user, quiz=quiz)
q = old_paper.current_question()
@@ -500,6 +501,19 @@ def show_all_users(request):
print context
return my_render_to_response('exam/showusers.html',context,context_instance=RequestContext(request))
+def quizlist(request):
+ """Generates a list of all the quizzes that are active for the students to attempt."""
+
+ quizzes = Quiz.objects.all()
+ context = {'papers': [],
+ 'quiz': None,
+ 'quizzes':quizzes}
+ return my_render_to_response('exam/quizlist.html', context,
+ context_instance=RequestContext(request))
+
+
+
+
def show_all_quiz(request):
"""Generates a list of all the quizzes that are currently in the database."""
diff --git a/testapp/templates/exam/quizlist.html b/testapp/templates/exam/quizlist.html
new file mode 100644
index 0000000..9b1fd73
--- /dev/null
+++ b/testapp/templates/exam/quizlist.html
@@ -0,0 +1,24 @@
+{% extends "base.html" %}
+
+{% block title %} Quiz List {% endblock title %}
+
+{% block formtitle %} Quiz List {% endblock %}
+
+{% block pagetitle %} Online Test {% endblock %}
+
+{% block content %}
+{% if not quizzes and not quiz %}
+<center><h5> No quizzes available. </h5></center>
+{% endif %}
+
+{% if quizzes %}
+<form method="post" action="" name='frm'>
+{% csrf_token %}
+
+{% for quiz in quizzes %}
+<a href="{{URL_ROOT}}/exam/start/{{quiz.id}}/">{{ quiz.description }}</a><br>
+{% endfor %}
+</form>
+{% endif %}
+
+{% endblock %}