summaryrefslogtreecommitdiff
path: root/testapp
diff options
context:
space:
mode:
authorhardythe12012-02-21 12:38:38 +0530
committerhardythe12012-02-21 12:38:38 +0530
commit2b6b595ca8652696ab9059add8ea54661cab5f31 (patch)
tree39906c360056c2cafc65e088e7cc6115954b01df /testapp
parent6b608e174fbd9367c9453f7933b69a35516811d2 (diff)
downloadonline_test-2b6b595ca8652696ab9059add8ea54661cab5f31.tar.gz
online_test-2b6b595ca8652696ab9059add8ea54661cab5f31.tar.bz2
online_test-2b6b595ca8652696ab9059add8ea54661cab5f31.zip
views for editing quiz and questions
Diffstat (limited to 'testapp')
-rw-r--r--testapp/exam/forms.py2
-rw-r--r--testapp/exam/urls.py2
-rw-r--r--testapp/exam/views.py106
-rw-r--r--testapp/templates/exam/show_quiz.html2
-rw-r--r--testapp/templates/exam/showquestions.html2
5 files changed, 83 insertions, 31 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index f0c515a..1788a08 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -123,7 +123,7 @@ class QuizForm(forms.Form):
new_quiz.description=description
new_quiz.save()
-class AddQuestionForm(forms.Form):
+class QuestionForm(forms.Form):
summary = forms.CharField(max_length = 128)
description = forms.CharField(widget = forms.Textarea(attrs={'cols': 20, 'rows': 3}))
points = forms.FloatField()
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index 772a2f3..2187e58 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -5,7 +5,9 @@ urlpatterns = patterns('exam.views',
url(r'^login/$', 'user_login'),
url(r'^manage/$', 'prof_manage'),
url(r'^manage/addquestion/$', 'add_question'),
+ url(r'^manage/addquestion/(?P<question_id>\d+)/$', 'add_question'),
url(r'^manage/addquiz/$', 'add_quiz'),
+ url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', 'add_quiz'),
url(r'^manage/gradeuser/$', 'show_all_users'),
url(r'^manage/questions/$', 'show_all_questions'),
url(r'^manage/showquiz/$','show_all_quiz'),
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 80632d8..c2296f3 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -14,7 +14,7 @@ from django.db.models import Sum
# Local imports.
from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, User
-from exam.forms import UserRegisterForm, UserLoginForm, QuizForm , AddQuestionForm
+from exam.forms import UserRegisterForm, UserLoginForm, QuizForm , QuestionForm
from exam.xmlrpc_clients import code_server
from settings import URL_ROOT
@@ -90,45 +90,95 @@ def user_register(request):
{'form':form},
context_instance=RequestContext(request))
-def add_question(request):
- """To add a new question in the database. Create a new question and store it."""
-
- if request.method == "POST":
- form = AddQuestionForm(request.POST)
- if form.is_valid():
- data = form.cleaned_data
- form.save()
- return my_redirect("/exam/manage/questions/")
-
- else:
- return my_render_to_response('exam/add_question.html',
- {'form':form},
- context_instance=RequestContext(request))
- else:
- form = AddQuestionForm()
- return my_render_to_response('exam/add_question.html',
- {'form':form},
- context_instance=RequestContext(request))
-
-def add_quiz(request):
- """To add a new quiz. Create a new quiz and store it in the database."""
+def add_question(request,question_id=None):
+ """To add a new question in the database. Create a new question and store it."""
if request.method == "POST":
- form = QuizForm(request.POST)
+ form = QuestionForm(request.POST)
if form.is_valid():
data = form.cleaned_data
- form.save()
- return my_redirect("/exam/manage/showquiz")
+ if question_id == None:
+ form.save()
+ return my_redirect("/exam/manage/questions")
+ else:
+ d = Question.objects.get(id=question_id)
+ d.summary = form['summary'].data
+ d.description = form['description'].data
+ d.points = form['points'].data
+ d.test = form['test'].data
+ d.options = form['options'].data
+ d.type = form['type'].data
+ d.active = form['active'].data
+ d.save()
+ return my_redirect("/exam/manage/questions")
+
+ else:
+ return my_render_to_response('exam/add_question.html',
+ {'form':form},
+ context_instance=RequestContext(request))
+ else:
+ if question_id == None:
+ form = QuestionForm()
+ return my_render_to_response('exam/add_question.html',
+ {'form':form},
+ context_instance=RequestContext(request))
+ else:
+
+ d = Question.objects.get(id=question_id)
+ form = QuestionForm()
+ form.initial['summary']= d.summary
+ form.initial['description'] = d.description
+ form.initial['points']= d.points
+ form.initial['test'] = d.test
+ form.initial['options'] = d.options
+ form.initial['type'] = d.type
+ form.initial['active'] = d.active
+
+ return my_render_to_response('exam/add_question.html',
+ {'form':form},
+ context_instance=RequestContext(request))
+
+
+def add_quiz(request,quiz_id=None):
+ if request.method == "POST":
+ form = QuizForm(request.POST)
+ if form.is_valid():
+ data = form.cleaned_data
+ if quiz_id == None:
+ form.save()
+ return my_redirect("/exam/manage/showquiz")
+ else:
+ d = Quiz.objects.get(id=quiz_id)
+ d.start_date = form['start_date'].data
+ d.duration = form['duration'].data
+ d.active = form['active'].data
+ d.description = form['description'].data
+ d.save()
+ return my_redirect("/exam/manage/showquiz")
else:
return my_render_to_response('exam/add_quiz.html',
{'form':form},
context_instance=RequestContext(request))
else:
- form = QuizForm()
- return my_render_to_response('exam/add_quiz.html',
+ if quiz_id == None:
+ form = QuizForm()
+ return my_render_to_response('exam/add_quiz.html',
{'form':form},
context_instance=RequestContext(request))
+ else:
+
+ d = Quiz.objects.get(id=quiz_id)
+ form = QuizForm()
+ form.initial['start_date']= d.start_date
+ form.initial['duration'] = d.duration
+ form.initial['description']= d.description
+ form.initial['active'] = d.active
+
+ return my_render_to_response('exam/add_quiz.html',
+ {'form':form},
+ context_instance=RequestContext(request))
+
def prof_manage(request):
"""Take credentials of the user with professor/moderator rights/permissions and log in."""
diff --git a/testapp/templates/exam/show_quiz.html b/testapp/templates/exam/show_quiz.html
index bbea77f..2e9059d 100644
--- a/testapp/templates/exam/show_quiz.html
+++ b/testapp/templates/exam/show_quiz.html
@@ -35,7 +35,7 @@ function my_confirm(frm)
{% csrf_token %}
{% for quiz in quizzes %}
-<input type=checkbox name='quiz' value={{quiz.id}} />&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/monitor/{{quiz.id}}/">{{ quiz.description }}</a><br>
+<input type=checkbox name='quiz' value={{quiz.id}} />&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquiz/{{quiz.id}}/">{{ quiz.description }}</a><br>
{% endfor %}
<br><br>
<button class="btn" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button>&nbsp;&nbsp;<button class="btn" type="submit" name="delete" onClick="my_confirm(frm);">Delete</button>
diff --git a/testapp/templates/exam/showquestions.html b/testapp/templates/exam/showquestions.html
index 38d4bcc..994ca26 100644
--- a/testapp/templates/exam/showquestions.html
+++ b/testapp/templates/exam/showquestions.html
@@ -26,7 +26,7 @@ function my_confirm(frm)
<form name=frm action="" method="post">
{% csrf_token %}
{% for i in questions %}
-<input type="checkbox" name="question" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/showquestions/{{ i.id }}">{{ i }}</a><br>
+<input type="checkbox" name="question" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{ i }}</a><br>
{% endfor %}
<br>
<button class="btn" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button>&nbsp;&nbsp;