diff options
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/urls.py | 1 | ||||
-rw-r--r-- | testapp/exam/views.py | 62 |
2 files changed, 46 insertions, 17 deletions
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 |