From f6a90c1eb603c9f3b8178102e387025880c0a5ac Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Mon, 20 Feb 2012 19:51:58 +0530 Subject: changes to manage questions --- testapp/exam/urls.py | 1 + testapp/exam/views.py | 62 +++++++++++++++++++++++--------- testapp/templates/exam/add_question.html | 2 +- testapp/templates/exam/grade_user.html | 6 ++-- testapp/templates/exam/monitor.html | 2 +- testapp/templates/exam/showusers.html | 3 +- testapp/templates/exam/user_data.html | 8 ++--- testapp/templates/manage.html | 4 +-- 8 files changed, 59 insertions(+), 29 deletions(-) (limited to 'testapp') diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index 72c93fa..504a4e6 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -7,6 +7,7 @@ urlpatterns = patterns('exam.views', url(r'^manage/addquestion/$', 'add_question'), url(r'^manage/addquiz/$', 'add_quiz'), url(r'^manage/gradeuser/$', 'show_all_users'), + url(r'^manage/questions/$', 'show_all_questions'), url(r'^register/$', 'user_register'), url(r'^start/$', 'start'), url(r'^quit/$', 'quit'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index b202ff3..b8233b2 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -91,23 +91,23 @@ def user_register(request): context_instance=RequestContext(request)) def add_question(request): - - if request.method == "POST": - form = AddQuestionForm(request.POST) - if form.is_valid(): - data = form.cleaned_data - form.save() - return my_redirect("/exam/manage/addquestion/") - - 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)) + + 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): if request.method == "POST": @@ -355,6 +355,34 @@ def show_all_users(request): print context return my_render_to_response('exam/showusers.html',context,context_instance=RequestContext(request)) +def show_all_questions(request): + if request.method == 'POST': + data = request.POST.getlist('question') + if data == None: + questions = Question.objects.all() + context = {'papers': [], + 'question': None, + 'questions':questions} + return my_render_to_response('exam/showquestions.html', context, + context_instance=RequestContext(request)) + for i in data: + question = Question.objects.get(id=i).delete() + questions = Question.objects.all() + context = {'papers': [], + 'question': None, + 'questions':questions} + return my_render_to_response('exam/showquestions.html', context, + context_instance=RequestContext(request)) + + else: + """Show the list of available quiz""" + questions = Question.objects.all() + context = {'papers': [], + 'question': None, + 'questions':questions} + return my_render_to_response('exam/showquestions.html', context, + context_instance=RequestContext(request)) + def user_data(request, username): """Render user data.""" current_user = request.user diff --git a/testapp/templates/exam/add_question.html b/testapp/templates/exam/add_question.html index ae86ed1..2d42b34 100644 --- a/testapp/templates/exam/add_question.html +++ b/testapp/templates/exam/add_question.html @@ -21,7 +21,7 @@ table th, table td { {{ form.as_table }}